What is the difference between bind and call in JavaScript?
call invokes a function now with a given this, while bind returns a new function for later. Learn the differences with examples and alternatives.
466 posts about JavaScript: questions with answers, tutorials and articles, newest first.
call invokes a function now with a given this, while bind returns a new function for later. Learn the differences with examples and alternatives.
call() takes arguments one by one, apply() takes them as an array. See examples, modern spread and bind alternatives, and common this pitfalls.
Classes are syntax over JavaScript's prototype chain. Learn how they map to prototypes and which extra rules and features classes add.
Learn every way to add properties to a JavaScript class: public and private fields, constructor assignment, accessors, static members and defineProperty.
Define instance, static, private and accessor methods in an ES2015+ class body, fix this binding, and know when to patch a prototype.
Create a JavaScript constructor with a class or a constructor function, understand what new does, and call super in subclasses.
Use extends and super to inherit from a class in JavaScript. Covers overriding, private fields, static methods, extending Error and when to prefer composition.
Use new with a class constructor to create independent instances that share methods through the prototype. Includes ES2022 private fields and factories.
Create a JavaScript class with class, constructor and methods, then add private fields, static members and inheritance with extends and super.
sort() orders array elements by a comparison rule, while reverse() just flips the current order. Both mutate the array, and ES2023 adds copying versions of each.
slice() returns a copy of part of an array, while splice() removes, replaces or inserts items in the original. Examples, pitfalls and the non-mutating toSpliced().
reduce() processes an array left to right and reduceRight() goes right to left. See when the order matters, with practical examples.
filter() returns a new array of all matching elements, while find() returns the first match or undefined. Compare return values, speed and use cases with examples.
forEach() runs a function for side effects and returns undefined, while map() returns a new transformed array. See examples, pitfalls with async code and when to use each.
Use the spread syntax or concat() to merge two JavaScript arrays into a new one, or push(...) to append in place. This guide compares each approach with examples.
Array.reduce() folds an array into one value. See sum, grouping and flattening examples, the empty array error and when map, filter or flat fit better.
Array.prototype.map() runs a callback on every element and returns a new array without changing the original. Learn syntax, object mapping, async use and pitfalls.
Array.prototype.filter() returns a new array with the elements that pass a test. See examples for objects, duplicates, chaining and async pitfalls.
Use reverse() to mutate an array or toReversed() (ES2023) for a new one. Includes string reversal, copies for older runtimes and common pitfalls.
Learn why JavaScript sort() orders numbers as strings, how to write comparators for numbers, text and objects, and when to use toSorted().