JavaScript ES2019 Version (2019)
JavaScript ES2019 (ECMAScript 2019) is the tenth major release of the JavaScript language specification. It was finalized in June 2019. ES2019 introduced several new features and enhancements to JavaScript, building upon the foundation laid by ES6 (ES2015). In this tutorial, we will learn about the new features introduced in ES2019 and how to use them in your JavaScript code.
Features of ES2019
ES2019 introduced several new features and enhancements to JavaScript. Some of the key features of ES2019 are:
-
Array.prototype.flat() and Array.prototype.flatMap(): ES2019 introduced the
Array.prototype.flat()
andArray.prototype.flatMap()
methods for working with nested arrays. Theflat()
method flattens a nested array to a specified depth, while theflatMap()
method maps each element using a mapping function and then flattens the result to a depth of 1.For example:
Array.prototype.flat() and Array.prototype.flatMap() Examplelet nestedArray = [1, [2, [3, 4], 5]];
console.log(nestedArray.flat()); // Output: [1, 2, [3, 4], 5]
let array = [1, 2, 3, 4, 5];
console.log(array.flatMap((x) => [x, x * 2])); // Output: [1, 2, 2, 4, 3, 6, 4, 8, 5, 10] -
Object.fromEntries(): ES2019 introduced the
Object.fromEntries()
method, which allows you to create an object from an iterable of key-value pairs. It takes an iterable (such as an array) of key-value pairs and returns a new object with those key-value pairs.For example:
Object.fromEntries() Examplelet entries = [
["name", "Alice"],
["age", 30],
];
let person = Object.fromEntries(entries);
console.log(person); // Output: { name: 'Alice', age: 30 } -
String.prototype.trimStart() and String.prototype.trimEnd(): ES2019 introduced the
String.prototype.trimStart()
andString.prototype.trimEnd()
methods, which allow you to trim whitespace characters from the start and end of a string, respectively. These methods are also known asString.prototype.trimLeft()
andString.prototype.trimRight()
.For example:
String.prototype.trimStart() and String.prototype.trimEnd() Examplelet str = " Hello ";
console.log(str.trimStart()); // Output: 'Hello '
console.log(str.trimEnd()); // Output: ' Hello' -
Symbol.prototype.description: ES2019 introduced the
Symbol.prototype.description
property, which allows you to access the description of aSymbol
. The description is the optional string that was provided when theSymbol
was created.For example:
Symbol.prototype.description Examplelet sym = Symbol("foo");
console.log(sym.description); // Output: 'foo'
Browser Support for ES2019
Most modern web browsers support ES2019 features, but some older browsers may not fully support all ES2019 features. To ensure that your JavaScript code works across all browsers, you can use a transpiler like Babel to convert your ES2019 code into ES5 code, which is compatible with older browsers.
ES2019 features are generally well-supported in modern web browsers, and you can start using them in your JavaScript code without the need for a transpiler in most cases.
For more information on browser support for ES2019 features, you can check the table.
73+ | 69+ | 12.1+ | 79+ | 60+ | No | |||||||
Latest ✅ | Latest ✅ | Latest ✅ | Latest ✅ | Latest ✅ | Latest ❌ |
Conclusion
ES2019 introduced several new features and enhancements to JavaScript, making it easier and more convenient to work with arrays, objects, strings, and symbols. By using ES2019 features, you can write more concise and expressive JavaScript code. Most modern web browsers support ES2019 features, allowing you to use them in your JavaScript code without the need for a transpiler in most cases.