JS 2019 - ECMAScript 2019
Last Updated :
24 Aug, 2023
ECMAScript 2019, also known as ES10, introduced features like Array.flat(), Array.flatMap(), Object.fromEntries(), and Symbol. description, and some string methods, for enhancing JavaScript's capabilities and expressiveness.
JavaScript 2019 (ES10) or ECMAScript 2019 new features are:
Name
| Description
|
String.trimStart() | trimming leading whitespace characters from a string.
|
String.trimEnd() | removes trailing whitespace characters from the end of a string
|
Object.fromEntries | Creates an object from a key-value pairs array.
|
Optional catch binding | omitting the catch parameter in try-catch blocks, simplifying error handling
|
Array.flat() | flattening nested arrays to a single-dimensional array.
|
Array.flatMap() | mapping and flattening nested arrays simultaneously for streamlined operations.
|
Revised Array.Sort() | Equal value elements retain relative positions during sorting.
|
Revised JSON.stringify() | safely handles UTF-8 code points (U+D800 to U+DFFF) accurate compatibility with JSON.parse().
|
Separator symbols allowed in string litterals | separator symbols are allowed within numeric and string literals to improve readability without affecting their values
|
Revised Function.toString() | converts a function to a string representation
|
We will explore all the above methods along with their basic implementation with the help of examples.
This method is used to trims leading whitespace characters from the beginning of a string, enhancing JavaScript's string manipulation capabilities for improved data handling and formatting.
Syntax:
string.trimStart();
Example: Here the basic example of String.trimStart().
JavaScript
let text = " GeeksforGeeks";
let result = text.trimStart();
console.log(result);
This method is used to removes trailing whitespace characters from the end of a string, offering enhanced string manipulation capabilities for improved data handling and formatting in JavaScript.
Syntax:
string.trimEnd()
Example: Here is the basic example String.trimEnd().
JavaScript
let text = "GeeksforGeeks ";
let result = text.trimEnd();
console.log(result);
Object.fromEntries() converts an array of key-value pairs into an object, simplifying object creation from structured data in JavaScript.
Syntax:
Object.fromEntries( iterable );
Example: In this example we are using the above-explained method.
JavaScript
const data = [
['name', 'Nikita'],
['age', 21],
['city', 'Noida']
];
let result = Object.fromEntries(data);
console.log(result);
Output{ name: 'Nikita', age: 21, city: 'Noida' }
Optional catch binding in ECMAScript 2019 allows omitting the catch parameter in try-catch blocks, simplifying error handling when the caught error object isn't needed.
Syntax:
try {
// Code that may throw an error
} catch (error) {
// Code that may throw an error
}
Example: Here is the basic example of using try and catch method.
JavaScript
function geekFunc() {
let a = 10;
try {
console.log("Value of variable a is : " + a);
}
catch (e) {
console.log("Error: " + e.description);
}
}
geekFunc();
OutputValue of variable a is : 10
Array.flat() method collapses nested arrays within an array to a single-dimensional array, simplifying array manipulation and enhancing data processing in JavaScript.
Syntax:
arr.flat([depth])
Example: In this example we are using the above-explained method.
JavaScript
// Creating multilevel array
let numbers = [['1', '2'], ['3', '4',
['5', ['6'], '7']]];
const flatNumbers = numbers.flat(Infinity);
console.log(flatNumbers);
Output[
'1', '2', '3',
'4', '5', '6',
'7'
]
Array.flatMap() combines mapping and flattening of nested arrays within an array, simplifying data transformation and manipulation by applying a function and then flattening the result.
Syntax:
let A = array.flatMap(function callback(current_value, index, Array)) {
// It returns the new array's elements.
}
Example: In this example, the flatMap() method applies a function to each element of the num1 array, doubling and squaring each number, and then flattens the resulting arrays into a single-dimensional array.
JavaScript
const num1 = [1, 2, 3, 4];
const result =
num1.flatMap(number => [number * 2, number ** 2]);
console.log(result);
Output[
2, 1, 4, 4,
6, 9, 8, 16
]
Method 7: Revised Array.Sort() Method
After ES2019, Array.sort() maintains relative positions of elements with equal values, ensuring stability in sorting algorithms for consistent results when sorting elements based on a value.
Syntax:
arr.sort(compareFunction)
Example:
JavaScript
const students = [
{ name: 'Anil', score: 85 },
{ name: 'Balram', score: 90 },
{ name: 'Chinu', score: 85 },
{ name: 'Dinesh', score: 78 },
];
// Sort by score in ascending order
students.sort((a, b) => a.score - b.score);
console.log(students);
Output[
{ name: 'Dinesh', score: 78 },
{ name: 'Anil', score: 85 },
{ name: 'Chinu', score: 85 },
{ name: 'Balram', score: 90 }
]
Before ES2019, JSON.stringify() broke UTF-8 code points (U+D800 to U+DFFF). Post-revision, it them, ensuring accurate conversion and compatibility with JSON.parse().
Syntax:
let text = JSON.stringify("\u26D4");
Example: In this example we are using the above-explained method.
JavaScript
let jsonStr1 = JSON.stringify('Hello\uD83D\uDE00Geeks');
let result = JSON.parse(jsonStr1);
console.log(result);
Method 9: Separator Symbols Allowed in String Litterals
In JavaScript ES2019, separator symbols (underscores) are allowed within numeric and string literals to improve readability without affecting their values or behavior.
Syntax:
let num1 = 1_000_000_000;
let str1 = 'Hello_World';
let text1 = "\u2028";
Example: In this example we are using the above mentioned methods.
JavaScript
let num1 = 1_000_000_000;
let str1 = 'Hello_World';
let text1 = "\u2028";
console.log(num1);
console.log(str1);
console.log(text1);
Output1000000000
Hello_World
Method 10: Revised Function.toString() Method
Function.toString() converts a function to a string representation, revealing its source code, including comments and formatting, facilitating debugging and dynamic code generation in JavaScript.
Syntax:
let result = myFunction.toString();
Example: Here the basic example of above mentioned method.
JavaScript
function myFunction(name) {
return `Hello, Geeks!`;
}
let result = myFunction.toString();
console.log(result);
Outputfunction myFunction(name) {
return `Hello, Geeks!`;
}
Supported browser:
- Chrome 1
- Edge 12
- Firefox 1
- Safari 1
- Opera 3
Similar Reads
JavaScript ES5 (JS 2009)
JavaScript 2009 (ES5) refers to the fifth edition of the ECMAScript language specification, standardized in 2009. It introduced several features, like strict mode, new methods, JSON support, and improved syntax for better programming practices and compatibility across browsers. ECMAScript 5 (ES5) in
7 min read
ES2015: Latest Version of JavaScript
ES2015 is the latest version of JavaScript programming language. It is the first major upgrade to JavaScript since 1997. It was approved in June 2015 by ECMA international, an association responsible for approving ECMA standards which programming languages like JavaScript, CoffeeScript and TypeScrip
4 min read
JS 2015 or ECMAScript 6 (ES6)
JS 2015 (ES6) also known as ECMAScript 6 (ES6), ECMAScript 6 (ES6) is a significant update to JavaScript, introducing arrow functions, classes, template literals, let and const for variable declaration, enhanced object literals, destructuring, and more modern features for better code organization an
10 min read
JS 2016 or ECMAScript 2016
JavaScript 2016 (ES2016) is a modified version of ES2015 in which they introduced some new features like JavaScript Exponentiation (**) operator, JavaScript Exponentiation assignment (**=), and Array..includes() method for array element presence checking, enhancing calculations, and array operations
2 min read
JS 2017 - ECMAScript 2017
JavaScript (JS) 2017, or ECMAScript 2017, introduced some new features in JavaScript. It enhanced asynchronous programming with async functions, provided shared memory and atomics for improved concurrency, and introduced Object.values() and Object.entries() for streamlined object manipulation. These
3 min read
JS 2018 - ECMAScript 2018
JavaScript 2018 (ES9) or ECMAScript 2018 is a modified version of ES8, in which ES9 introduced new features like asynchronous iteration, rest/spread properties, and enhancements to regular expressions, further improving asynchronous programming, object manipulation, and string handling capabilities.
4 min read
JS 2019 - ECMAScript 2019
ECMAScript 2019, also known as ES10, introduced features like Array.flat(), Array.flatMap(), Object.fromEntries(), and Symbol. description, and some string methods, for enhancing JavaScript's capabilities and expressiveness. JavaScript 2019 (ES10) or ECMAScript 2019 new features are: Name Descriptio
5 min read
JS 2020 - ECMAScript 2020
JavaScript ECMAScript 2020 (ES11) introduced new features like optional chaining, nullish coalescing, dynamic import(), BigInt, and Promise.allSettled(), etc. enhancing language capabilities for modern web development needs. JavaScript 2020 (ES11) or ECMAScript 2020 new features are: BigInttype for
5 min read
ECMAScript 2021 (JS 2021/2022)
JavaScript in 2021/2022 continues to evolve, with ES2021/ES2022 bringing enhanced features like private class fields, promise improvements, and record data structures, boosting developer productivity and code quality. JavaScript New Features in ES2021Name Description Promise any(): Resolves if any P
4 min read
New Features in ECMAScript 2021 Update
ECMAScript is a part of JavaScript language which is mostly used in web technology, building websites, or web apps. ECMAScript is growing as one of the world's most widely used general-purpose programming languages. It is majorly used in embedding with web browsers and is also adopted for server and
4 min read