What Is JavaScript? A Beginner's Guide with Examples
JavaScript is the language that makes web pages interactive and also runs on servers. See how it works, with the DOM, fetch and Node.js examples.
466 posts about JavaScript: questions with answers, tutorials and articles, newest first.
JavaScript is the language that makes web pages interactive and also runs on servers. See how it works, with the DOM, fetch and Node.js examples.
Detect features instead of browsers, set a browserslist target, transpile and polyfill only what you need, and test in Chromium, Firefox and WebKit.
Select elements with querySelector, change content, classes and attributes, create and remove nodes, and handle events safely with modern DOM APIs.
The DOM represents the document you can modify, while the BOM gives access to the browser itself. Learn the objects, the hierarchy and modern best practice.
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.