Skip to main content

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:

  1. Array.prototype.flat() and Array.prototype.flatMap(): ES2019 introduced the Array.prototype.flat() and Array.prototype.flatMap() methods for working with nested arrays. The flat() method flattens a nested array to a specified depth, while the flatMap() 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() Example
    let 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]
  2. 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() Example
    let entries = [
    ["name", "Alice"],
    ["age", 30],
    ];
    let person = Object.fromEntries(entries);
    console.log(person); // Output: { name: 'Alice', age: 30 }
  3. String.prototype.trimStart() and String.prototype.trimEnd(): ES2019 introduced the String.prototype.trimStart() and String.prototype.trimEnd() methods, which allow you to trim whitespace characters from the start and end of a string, respectively. These methods are also known as String.prototype.trimLeft() and String.prototype.trimRight().

    For example:

    String.prototype.trimStart() and String.prototype.trimEnd() Example
    let str = "   Hello   ";
    console.log(str.trimStart()); // Output: 'Hello '
    console.log(str.trimEnd()); // Output: ' Hello'
  4. Symbol.prototype.description: ES2019 introduced the Symbol.prototype.description property, which allows you to access the description of a Symbol. The description is the optional string that was provided when the Symbol was created.

    For example:

    Symbol.prototype.description Example
    let 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.

ChromeFirefoxSafariEdgeOperaInternet Explorer
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.