Pigułka wiedzy
Masz 30 sekund? Super, tyle właśnie wystarczy, by nauczyć się czegoś nowego!
Optional Chaining: The Safe Way to Access Data
You can avoid „Cannot read property of undefined” errors by using optional chaining, which safely checks whether a value exists before accessing its properties.
const city = user?.profile?.address?.city ?? "Unknown";
Optional chaining lets you navigate deeply nested objects without writing multiple defensive checks – clean, safe, and modern.
Write Cleaner Code with Guard Clauses
Instead of writing nested if statements, you can use guard clauses – early-return checks that immediately stop the function when the input is invalid. This makes your code cleaner, easier to read, and much easier to maintain.
function processString(value) {
if (typeof value !== 'string') return null;
if (value.length <= 3) return null;
return value.toUpperCase();
}
Keep Only What You Need with .filter()
You can use .filter() to instantly remove unwanted items from an array while keeping the original array unchanged.
const positives = numbers.filter(n => n > 0);
.filter() returns a new array – perfect for cleanup, searches, and simple validations.
Level Up Your Arrays with .map()
You can use .map() to instantly transform every item in an array into something new — without mutating the original one.
const labels = numbers.map(n => `Item: ${n}`);
.map() always returns a new array, making transformations clean and predictable.
The Difference Between == and === in JavaScript
The loose equality operator == in JavaScript automatically converts values to the same type before comparing them.
This can cause unexpected results, so it’s usually better to use the strict equality operator ===
console.log(5 == "5");
// true - because "5" is converted to a number
console.log(5 === "5");
// false - because types are different (number vs string)
Boost Scroll Performance with passive: true
Make scroll or touch listeners more performant – tell the browser you won’t call preventDefault()
window.addEventListener(
'scroll',
onScroll,
{ passive: true }
);
Destructure and Keep the Rest
You can combine destructuring and rest syntax to extract what you need and keep the rest.
const { id, ...info } = { id: 1, name: "Alice", role: "Admin" };
console.log(info); // { name: "Alice", role: "Admin" }
Run an Event Listener Just Once
You can make an event listener run only once – it removes itself automatically after the first trigger.
button.addEventListener(
'click',
handler,
{ once: true }
);
Powyższy zestaw ciekawostek z zakresu programowania to szybka porcja wiedzy w pigułce, dla zabieganych programistów, bez lania wody, bez zbędnej teorii – tylko czyste, skondensowane info w stylu „Czy wiesz, że …”
Dostrzeżesz tu zarówno podstawy, które każdy programista wiedzieć powinien, (przynajmniej w teorii, ale bądźmy szczerzy – pamięć mamy dobrą, ale krótką i bez google albo AI momentami byłoby ciężko), jak i programistyczne „smaczki”, przyprawiające o nerwowy śmiech nawet doświadczonych developerów. Niezależnie, czy jesteś początkującym koderem, doświadczonym devem, czy po prostu lubisz klikać w rzeczy, które wyglądają mądrze – znajdziesz tu coś dla siebie.
Przygotuj się na uśmiech, przebłyski myśli: „aaa, o to chodzi!” oraz stan „ooo, dobrze wiedzieć…”
UWAGA ! Możliwe efekty uboczne: nagłe oświecenie programistyczne oraz niepohamowana chęć dzielenia się wiedzą z każdym napotkanym developerem.