Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS 2024

JavaScript Version Numbers

Earlier ECMAScript versions were named by numbers, such as ES5 and ES6.

Since 2016, versions have been named by year, like ES2016, ES2018, and ES2020.

The 15th edition, ECMAScript 2024, is set to be published in July 2024.

New Features in ES2024

  • Object.groupBy()
  • Map.groupBy()
  • Temporal.PlainDate()
  • Temporal.PlainTime()
  • Temporal.PlainMonthDay()
  • Temporal.PlainYearMonth()

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);

Description

The Object.groupBy() method groups the elements of an object based on string values returned by a callback function.

This method does not modify the original object.

Note:
The elements in both the original and returned objects are the same. Any changes made will be reflected in both the original and the returned object.

JavaScript Map.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 = Map.groupBy(fruits, myCallback);

Description

The Map.groupBy() method groups the elements of a Map based on string values returned by a callback function.

This method does not modify the original Map object.

Note:

The elements in both the original and returned objects are identical. Any changes made will be reflected in both the original and the returned object.