Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Variables JS Let JS Const JS Types

JS Operators

JS Operators JS Arithmetic JS Assignment JS Comparisons JS Conditional JS If JS If Else JS Ternary JS Switch JS Booleans JS Logical

JS Loops

JS Loops JS Loop for JS Loop while JS Break JS Continue JS Control Flow

JS Strings

JS Strings JS String Templates JS String Methods JS String Search JS String Reference

JS Numbers

JS Numbers JS Numbers JS Number Methods JS Number Properties JS Number Reference JS Bitwise JS BigInt

JS Functions

Function Path Function Intro Function Invocation Function Parameters Function Returns Function Arguments Function Expressions Function Arrow Function Quiz

JS Objects

Object Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors

JS Scope

JS Scope JS Code Blocks JS Hoisting JS Strict Mode

JS Dates

JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods

JS Arrays

JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const

JS Sets

JS Sets JS Set Methods JS Set Logic JS Set WeakSet JS Set Reference

JS Maps

JS Maps JS Map Methods JS Map WeakMap JS Map Reference

JS Iterations

JS Loops JS Iterables JS Iterators JS Generators

JS Math

JS Math JS Math Reference JS Math Random

JS RexExp

JS RegExp Flags JS RegExp Classes JS RegExp Metachars JS RegExp Assertions JS RegExp Quantifiers JS RegExp Patterns JS RegExp Objects JS RegExp Methods

JS Data Types

JS Destructuring JS Data Types JS Primitive Data JS Object Types JS typeof JS toString() JS Type Conversion

JS Errors

JS Errors Intro JS Errors Silent JS Error Statements JS Error Object

JS Debugging

JS Debugging Debugging Debug Console Debug Breakpoints Debug Errors Debug Async

JS Conventions

JS Style Guide JS Best Practices JS Mistakes JS Performance

JS References

JS Keywords Reference JS Keywords Reserved JS Operator Reference JS Operator Precedence

JS Versions

JS 2026 JS 2025 JS 2024 JS 2023 JS 2022 JS 2021 JS 2020 JS 2019 JS 2018 JS 2017 JS 2016 JS Versions JS 2015 (ES6) JS 2009 (ES5) JS 1999 (ES3) JS IE / Edge JS History

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Temporal  New JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


ECMAScript 2024


New Features in JavaScript 2024

FeatureDescription
Object.groupBy() Groups object elements according to values returned from a callback function
Map.groupBy() Groups map elements according to values returned from a callback function
String isWellFormed() Returns true if a string is well formed
String.toWellFormed() Returns a new string where "lone surrogates" are replaced with Unicode U+FFFD
Promise.withResolvers()
Atomics
waitAsync

Warning

These features are relatively new.

Older browsers may need an alternative code (Polyfill)


JavaScript Object.groupBy()

Example

// Create an Array
const fruits = [
  {name:"apples", quantity:300},
  {name:"bananas", quantity:500},
  {name:"oranges", quantity:200},
  {name:"kiwi", quantity:150}
];

// Callback function to Group Elements
function myCallback({ quantity }) {
  return quantity > 200 ? "ok" : "low";
}

// Group by Quantity
const result = Object.groupBy(fruits, myCallback);
Try it Yourself »

Description

The Object.groupBy() method groups elements of an object according to string values returned from a callback function.

The Object.groupBy() method return a new object.

The Object.groupBy() method does not change the original object.

Note:

The elements in the original and in the returned object are the same.

Future changes will be reflected in both the original and in the returned object.


JavaScript Map.groupBy()

Example

// Create a Map
const fruits = [
  {name:"apples", quantity:300},
  {name:"bananas", quantity:500},
  {name:"oranges", quantity:200},
  {name:"kiwi", quantity:150}
];

// Callback function to Group Elements
function myCallback({ quantity }) {
  return quantity > 200 ? "ok" : "low";
}

// Group by Quantity
const result = Map.groupBy(fruits, myCallback);
Try it Yourself »

Description

The Map.groupBy() method groups elements of a map according to string values returned from a callback function.

The Map.groupBy() method returns a new map.

The Map.groupBy() method does not change the original object.

Note:

The elements in the original and in the returned object are the same.

Future changes will be reflected in both the original and in the returned object.


Object.groupBy() vs Map.groupBy()

The difference between Object.groupBy() and Map.groupBy() is:

Object.groupBy() groups elements into a JavaScript object.

Map.groupBy() groups elements into a Map object.



JavaScript String isWellFormed()

The isWellFormed() method returns true if a string is well formed.

Otherwise it returns false.

A string is not well formed if it contains lone surrogates.

Examples

let text = "Hello world!";
let result = text.isWellFormed();
Try it Yourself »
let text = "Hello World \uD800";
let result = text.isWellFormed();
Try it Yourself »

Lone Surrogates

A lone surrogate is a Unicode surrogate code point that is not part of a valid surrogate pair used to represent characters in UTF-16 encoding.


JavaScript String toWellFormed()

The String method toWellFormed() returns a new string where all "lone surrogates" are replaced with the Unicode replacement character (U+FFFD).

Examples

let text = "Hello World \uD800";
let result = text.toWellFormed();
Try it Yourself »

JavaScript Promise.withResolvers()

Promise.withResolvers() is a static method that simplifies the creation and management of Promises.

Promise.withResolvers() provides a more convenient way to access the resolve and reject functions associated with a Promise outside of its executor function.

Instead of the traditional new Promise((resolve, reject) => { ... }) constructor pattern, Promise.withResolvers() returns an object containing:

  • promise: The newly created Promise instance
  • resolve: A function to fulfill the promise with a value
  • reject: A function to reject the promise with a reason (error)

Example

<p id="demo">Waiting...</p>

<script>
const {promise, resolve, reject} = Promise.withResolvers();

// You can now use 'resolve' and 'reject' anywhere
// in your code to control the state of 'promise'.

// Simulate async work
setTimeout(() => {
  const success = Math.random() > 0.5;
  if (success) {
    resolve("Operation successful!");
  } else {
    reject("Operation failed!");
  }
}, 1000);

// Update the UI when the promise finishes
promise
  .then((message) => {
    document.getElementById("demo").innerHTML = message;
  })
  .catch((error) => {
    document.getElementById("demo").innerHTML = error; ;
  });
</script>
Try it Yourself »

Example Explained

  • The <p id="demo"> initially shows "Waiting..."
  • After 1 second, the promise resolves or rejects
  • The result is written into "demo"

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->