en.javascript.info
en.javascript.info copied to clipboard
Modern JavaScript Tutorial
# [Patterns and flags](https://javascript.info/regexp-introduction) ECMAScript 2022 introduced a new flag for regular expressions: `d`. Here are some sources describing the behavior of this flag: - https://stackoverflow.com/a/73947884 - https://www.dotnetcurry.com/javascript/ecmascript-2022#:~:text=RegExp%20Match%20Indices - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices#:~:text=The%20d%20flag%20indicates%20that%20the%20result%20of%20a%20regular%20expression%20match%20should%20contain%20the%20start%20and%20end%20indices%20of%20the%20substrings%20of%20each%20capture%20group.%20It%20does%20not%20change%20the%20regex's%20interpretation%20or%20matching%20behavior%20in%20any%20way,%20but%20only%20provides%20additional%20information%20in%20the%20matching%20result.
# [Nullish coalescing operator '??'](https://javascript.info/nullish-coalescing-operator) ECMAScript 2021 introduced the **nullish assignment operator `??=`**. ```javascript x ??= y; // x ?? (x = y); ```
The task was to create a function `sortByAge(users)` (using `users` as parameter). Now also the solution reflects that.
According to this SVG:  ...There should be one more line in the code below: ```diff let list = { value: 1 }; list.next = { value: 2 }; list.next.next...
# [JSON methods, toJSON](https://javascript.info/json) ```diff let json = `{ *!*name*/!*: "John", // mistake: property name without quotes "surname": *!*'Smith'*/!*, // mistake: single quotes in value (must be double) *!*'isAdmin'*/!*: false,...
# [Window sizes and scrolling](https://javascript.info/size-and-scroll-window) The article is missing information regarding the optional `options` object, which can be used in `scrollTo`/`scrollBy`/`scrollIntoView` methods, for example, to make scrolling smooth: ```javascript window.scrollBy({...
# [Cross-window communication](https://javascript.info/cross-window-communication) Code: ```javascript iframe.onload = function() { // we can get the reference to the inner window let iframeWindow = iframe.contentWindow; // OK try { // ...but not...
# [Logical operators](https://javascript.info/logical-operators) **ECMAScript 2021** introduced logical assignment operators: - `||=` ([Logical OR assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment)) - `&&=` ([Logical AND assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment)) This PR adds a description of the new operators, and one...