JavaScript Knowledge Base
Concise guides on the JavaScript concepts used in exercises.
JavaScript Set Methods: union, intersection, and difference
Learn JavaScript Set methods like union, intersection, difference, symmetricDifference, and subset checks with practical examples.
RegExp.escape in JavaScript
Learn how RegExp.escape safely inserts user text into dynamic regular expressions, and why hand-rolled escaping misses edge cases.
Optional Chaining and Nullish Coalescing in JavaScript
Learn optional chaining and nullish coalescing in JavaScript with nested objects, safe calls, fallbacks, and mistakes that hide bugs.
Object Destructuring in JavaScript
Learn object destructuring in JavaScript with renaming, defaults, function parameters, rest properties, and missing-property bugs.
addEventListener in JavaScript
Learn addEventListener in JavaScript with callback references, event objects, removeEventListener, one-time listeners, and the eager-handler bug.
Object.keys, Object.values, and Object.entries: How to Choose
Choose Object.keys, Object.values, Object.entries, and Object.fromEntries by the shape of object data you need.
What Is Polyfilling in JavaScript?
Learn what polyfilling means in JavaScript, how it differs from transpiling, and why missing APIs need runtime fallbacks.
How Event Delegation Works in JavaScript
Learn how event delegation works in JavaScript, why bubbling makes it possible, and how to use target, currentTarget, and closest safely.
Event Bubbling in JavaScript Explained with target and currentTarget
Learn event bubbling in JavaScript, why parent listeners run after child clicks, and how target differs from currentTarget in real handlers.
querySelector vs querySelectorAll: What Is the Difference?
Learn when to use querySelector, when to use querySelectorAll, and why querySelectorAll returns a NodeList instead of an array.
textContent vs innerHTML vs innerText in JavaScript
Learn when to use textContent, innerHTML, and innerText for DOM updates, plus the security and rendering traps behind each property.
JavaScript Tasks vs Microtasks: Why Promises Run Before setTimeout
Learn JavaScript tasks vs microtasks, the event loop, Promise.then ordering, and why setTimeout(0) still waits.
Why Async Functions Always Return a Promise
Learn why every async function returns a Promise, how returned values and thrown errors behave, and how to call async functions correctly.
Higher-Order Functions in JavaScript
Learn higher-order functions in JavaScript with callbacks, returned functions, closures, array methods, and the mistakes that make them confusing.
JavaScript Prototypes and the Prototype Chain
Learn how JavaScript prototypes, property lookup, constructor functions, classes, instanceof, and prototype pollution actually work.
JavaScript Closures
Learn JavaScript closures with scope, private state, callbacks, loop bugs, async code, memory retention, and practical examples.
Truthy and Falsy Values in JavaScript
Learn the real JavaScript falsy values, why empty arrays are truthy, and how to avoid fallback bugs with || and ??.
null vs undefined in JavaScript
Learn null vs undefined in JavaScript, where each value comes from, and how to write safer checks for missing data.
JavaScript Spread Operator
Learn how the JavaScript spread operator copies arrays, merges objects, passes arguments, and where shallow copies cause bugs.
When to Use some and every in JavaScript
Learn when to use some and every in JavaScript for boolean array checks, including short-circuiting, empty arrays, and validation rules.
forEach vs map in JavaScript
Learn the real difference between forEach and map in JavaScript: side effects, return values, async callbacks, and when a loop is clearer.
map vs filter vs find: How to Choose the Right Array Method
Learn how to choose between map, filter, and find by result shape, with examples for transformations, lists, one-record lookups, and common bugs.
JavaScript Array Methods
Learn when to use map, filter, reduce, find, some, and every without turning simple array code into a mystery pipeline.
Off-by-One Errors in JavaScript Loops
Learn why off-by-one errors happen in JavaScript loops, how array length and indexes differ, and how to debug loop boundaries.
break and continue in JavaScript
Learn how break and continue in JavaScript loops work, when to use each one, and the bugs they prevent or create.
JavaScript while Loops
Learn JavaScript while loops with conditions, updates, sentinels, infinite-loop bugs, break, and when while beats for.
JavaScript for...of Loop
Learn when to use the JavaScript for...of loop with arrays, strings, Maps, Sets, async code, break, continue, and Object.entries.
JavaScript for Loops
Learn JavaScript for loops with counters, conditions, array indexes, off-by-one bugs, break, continue, and safer loop choices.
JavaScript Switch Statements
Learn how JavaScript switch statements compare values, why break matters, and when switch is clearer than if...else.
JavaScript Ternary Operator
Learn when the JavaScript ternary operator makes conditional values clearer, and when nested ternaries should become if or switch logic.
JavaScript Arrow Functions
Learn how JavaScript arrow functions handle return values, this binding, arguments, and the cases where function syntax is still better.
JavaScript Template Literals
Learn how JavaScript template literals handle interpolation, multiline strings, tagged templates, and the escaping mistakes that cause bugs.
Default Parameters in JavaScript
Learn how JavaScript default parameters handle undefined, falsy values, call-time expressions, destructuring, and optional arguments.
Rest Parameters in JavaScript
Learn how JavaScript rest parameters collect arguments, replace arguments, differ from spread, and support flexible function APIs.
Parameters and Arguments in JavaScript
Learn parameters and arguments in JavaScript, including positional matching, missing values, defaults, rest parameters, and object inputs.
return vs console.log in JavaScript
Return vs console.log in JavaScript: learn what each one does, why logged values still return undefined, and when to use each.
JavaScript Operators by Intent
Learn JavaScript operators by the job they do: calculate, compare, choose, update, combine, and avoid clever-looking bugs.
JavaScript Comparison Operators
Learn how JavaScript comparison operators create booleans, why === beats ==, and where string, object, and NaN comparisons surprise people.
JavaScript Logical Operators
Learn how JavaScript logical operators combine conditions, short circuit, return values, and differ from ?? for safe fallbacks.
How typeof Works in JavaScript
Learn how typeof works in JavaScript, what strings it returns, why typeof null is object, and when Array.isArray or Number.isNaN is better.
let vs const in JavaScript
Learn when to use let vs const in JavaScript, what const actually protects, and why reassignment is the real distinction.
JavaScript Primitive Values Explained
Learn JavaScript primitive values, how they differ from objects, why strings have methods, and how null, undefined, symbols, and BigInts behave.
How to Trace JavaScript Code by Hand
Learn how to trace JavaScript code step by step with variables, loops, function calls, return values, array methods, and console output.
JSON.parse in JavaScript: Safe Parsing, Errors, and Fallbacks
Learn JSON.parse in JavaScript with SyntaxError handling, try/catch, fallback values, and the difference between parsing and validation.
Form submit Events and preventDefault in JavaScript
Learn how form submit events work in JavaScript, why forms reload by default, and how preventDefault lets you validate and render UI.
classList in JavaScript: add, remove, toggle, and contains
Learn how to use classList in JavaScript to manage DOM state with CSS classes without overwriting existing classes.
How to Cancel a Fetch Request with AbortController
Use AbortController to cancel fetch requests, handle AbortError safely, and avoid stale responses in timeouts and search UIs.
How to Handle fetch Errors Properly in JavaScript
Learn how to handle fetch errors with try/catch, response.ok, status codes, bad responses, and safe JSON parsing order.
DOMContentLoaded vs defer: Why DOM Code Runs Too Early
Learn when to use DOMContentLoaded vs defer, why DOM queries run too early, and how script loading affects querySelector and event setup.
How to Store Objects in localStorage with JSON
Store objects in localStorage safely with JSON.stringify, JSON.parse, fallbacks, and the limits of browser storage.
Why querySelector Returns Null and How to Fix It
Learn why querySelector returns null, how to debug selectors and timing, and how to write safer DOM selection code.
When to Use Promise.all, Promise.allSettled, Promise.race, and Promise.any
Choose the right Promise combinator by whether you need every result, every outcome, the first settlement, or the first success.
Why JavaScript sort() Mutates Arrays and How to Avoid It
Learn why JavaScript sort() mutates arrays, how to avoid accidental changes, and when to use toSorted, spread, or slice.
How to Use reduce in JavaScript Without Getting Confused
Learn JavaScript reduce with a clear accumulator mental model, trace tables, initial values, and practical rules for when not to use it.
JavaScript reduce Accumulator Patterns for Real Data
Use JavaScript reduce accumulator patterns for totals, counts, groups, indexes, averages, deduping, and safer real-world data summaries.
JavaScript Operator Precedence Without Guessing
Learn JavaScript operator precedence without memorizing a chart, using parentheses, named steps, and high-risk expression patterns.