Array.reduce vs Array.reduceRight in JavaScript
reduce folds an array from the first element, reduceRight from the last. Learn when direction matters, such as composition and subtraction.
466 posts about JavaScript: questions with answers, tutorials and articles, newest first.
reduce folds an array from the first element, reduceRight from the last. Learn when direction matters, such as composition and subtraction.
filter returns every match as a new array, find returns the first match or undefined. See examples, performance notes and related methods.
map builds a new array from each element, forEach only runs side effects and returns undefined. Learn when to use each and common mistakes.
Object.assign is a built-in shallow, mutating copy, and Object.merge is not part of JavaScript. Learn what to use for shallow and deep merges.
Object.create links a new object to a prototype of your choice and runs no code. The new operator runs a constructor and links the instance to its prototype property.
Object.freeze blocks all changes to an object, while Object.seal still lets you update existing values. Compare them with examples and a deep freeze helper.
`let` allows reassignment while `const` does not, though const objects can still change. Learn when to use each.
In browsers window is the global object, in Node.js it is global, and globalThis works everywhere. See which variable declarations become global properties and why.
preventDefault cancels default browser behaviour such as form submits, while stopPropagation stops an event bubbling or capturing to other elements. Learn when to use each.
Use addEventListener for all event handling. attachEvent was an IE-only legacy API removed from modern browsers; this guide compares the two and shows migration.
Capturing goes from the root down to the target and bubbling goes back up. See the order of listeners, the capture option and when each phase is useful.
Call event.preventDefault() in a listener to cancel actions like link navigation or form submission, and understand cancelable events and passive listeners.
Use addEventListener to respond to clicks, form submits and key presses, and learn bubbling, delegation and clean listener removal.
Build an Event or CustomEvent, dispatch it on a target and listen with addEventListener. Includes bubbling, cancelling and non-DOM EventTarget examples.
A JavaScript event is a signal that something happened in the browser. See how listeners, bubbling, delegation and custom events work, with modern examples.
fetch() does not reject on 404 or 500. Learn to check response.ok, add timeouts with AbortSignal, classify errors and retry transient failures.
Use fetch() with async/await for GET and POST requests, handle HTTP errors and timeouts correctly, and learn when XMLHttpRequest still makes sense.
Learn to handle JavaScript promises with then, catch, finally and async/await, run several in parallel with Promise.all, and avoid the most common mistakes.
Learn how new Promise works with resolve and reject, how to consume promises with await, and when to use Promise.all, allSettled, race and any.
Callbacks run when a task finishes, while promises represent a future value you can chain. Compare both with examples, async/await and conversion tips.