What is a higher-order function in JavaScript? Examples
A higher-order function takes a function, returns one, or both. See map, filter, reduce, closures, wrappers and composition with tested examples.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
A higher-order function takes a function, returns one, or both. See map, filter, reduce, closures, wrappers and composition with tested examples.
A closure is a function bundled with the scope where it was created. Learn how to create one and use it for private state and callbacks.
Local variables live inside a function or block; globals are visible everywhere and can clash. Learn scope rules, hoisting and best practice.
Synchronous functions block until they return, asynchronous ones finish later. See promises, async/await and the event loop in action.
for...in iterates property names as strings; for...of iterates values from iterables like arrays and maps. See examples and when to use each.
Template literals use backticks for interpolation with ${}, multi-line strings and tagged templates. Examples and common mistakes included.
Arrow functions inherit this and cannot be constructors, while function expressions get their own this and arguments. Compare them with clear examples.
toUpperCase is locale-independent, while toLocaleLowerCase follows locale rules such as Turkish dotted and dotless i. See examples and when to use each.
trimRight() removes trailing whitespace and is an alias of trimEnd(), while toLowerCase() changes letter case. See examples and how to combine them.
trimEnd() trims the end of a string, while trimLeft() is a legacy alias of trimStart() that trims the start. Learn which names to use in new code.
trim() cleans both ends of a string while trimStart() cleans only the beginning. Examples, what counts as whitespace and when to choose each.
concat() appends values to a string, while join() turns an array into one string with a separator. There is no String.join; learn when to use each.
split() turns a string into an array at each separator, while replace() returns a string with a match substituted. See replaceAll(), regex use and pitfalls.
slice() accepts negative indices and returns an empty string for reversed ranges, while substring() clamps negatives to 0 and swaps arguments. Examples included.
sort orders elements with an optional comparator, reverse flips the order, and both mutate the array. See the default string-sort trap and ES2023 alternatives.
slice returns a shallow copy of a range and never mutates; splice removes, replaces or inserts in place. Learn the arguments, pitfalls and toSpliced.
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.

How SPF, DKIM and DMARC work together to stop email spoofing, with example DNS records, alignment rules, and a step-by-step rollout plan.
map builds a new array from each element, forEach only runs side effects and returns undefined. Learn when to use each and common mistakes.