Skip to main content

JavaScript ES2020 Version (2020)

JavaScript ES2020 (ECMAScript 2020) is the eleventh major release of the JavaScript language specification. It was finalized in June 2020. ES2020 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 ES2020 and how to use them in your JavaScript code.

Features of ES2020

ES2020 introduced several new features and enhancements to JavaScript. Some of the key features of ES2020 are:

  1. BigInt: ES2020 introduced the BigInt primitive type, which allows you to represent arbitrarily large integers in JavaScript. The BigInt type is created by appending n to the end of an integer literal or by calling the BigInt() constructor with a numeric value.

    For example:

    BigInt Example
     const bigNumber = 1234567890123456789012345678901234567890n;
    console.log(bigNumber); // Output: 1234567890123456789012345678901234567890n
  2. Dynamic Import: ES2020 introduced dynamic import() expressions, which allow you to dynamically import modules in JavaScript. The import() function returns a Promise that resolves to the module namespace object of the requested module.

    For example:

    Dynamic Import Example
     const modulePath = './module.js';
    import(modulePath)
    .then((module) => {
    console.log(module.default);
    })
    .catch((error) => {
    console.error(error);
    });
  3. Nullish Coalescing Operator (??): ES2020 introduced the nullish coalescing operator (??), which allows you to provide a default value for variables that are null or undefined. The nullish coalescing operator returns the right-hand operand when the left-hand operand is null or undefined, and otherwise returns the left-hand operand.

    For example:

    Nullish Coalescing Operator Example
     const name = null;
    const defaultName = name ?? 'John Doe';
    console.log(defaultName); // Output: 'John Doe'
  4. Optional Chaining Operator (?.): ES2020 introduced the optional chaining operator (?.), which allows you to safely access nested properties of an object without having to check if each property exists. If a property is null or undefined, the optional chaining operator short-circuits and returns undefined.

    For example:

    Optional Chaining Operator Example
     const user = {
    name: 'Alice',
    address: {
    city: 'New York',
    },
    };

    console.log(user.address?.city); // Output: 'New York'
    console.log(user.address?.country); // Output: undefined
  5. Promise.allSettled(): ES2020 introduced the Promise.allSettled() method, which returns a Promise that resolves after all the input Promises have settled (either fulfilled or rejected). The Promise returned by Promise.allSettled() resolves with an array of objects that describe the outcome of each Promise.

    For example:

    Promise.allSettled() Example
     const promises = [
    Promise.resolve(1),
    Promise.reject(new Error('Error!')),
    Promise.resolve(3),
    ];

    Promise.allSettled(promises)
    .then((results) => {
    results.forEach((result) => {
    console.log(result.status, result.value);
    });
    });

Browser Support for ES2020

Most modern web browsers support ES2020 features, but some older browsers may not fully support all ES2020 features. To ensure that your JavaScript code works across all browsers, you can use a transpiler like Babel to convert your ES2020 code into ES5 code, which is compatible with older browsers.

ES2020 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 ES2020 features, you can check the table.

ChromeFirefoxSafariEdgeOperaInternet Explorer
85+79+14+79+71+No
Latest ✅Latest ✅Latest ✅Latest ✅Latest ✅Latest ❌
📝 Note
  • Chrome: 85+ (Latest ✅)

    Chrome has full support for ES2020 features. You can use ES2020 features in Chrome without any issues. Chrome 85 and later versions fully support ES2020 features. Chrome is the most popular web browser, and it is recommended to test your JavaScript code in Chrome to ensure compatibility.

  • Firefox: 79+ (Latest ✅)

    Firefox has full support for ES2020 features. You can use ES2020 features in Firefox without any issues. Firefox 79 and later versions fully support ES2020 features. Firefox is a popular web browser, and it is recommended to test your JavaScript code in Firefox to ensure compatibility.

  • Safari: 14+ (Latest ✅)

    Safari has full support for ES2020 features. You can use ES2020 features in Safari without any issues. Safari 14 and later versions fully support ES2020 features. Safari is a popular web browser on macOS and iOS devices, and it is recommended to test your JavaScript code in Safari to ensure compatibility.

  • Edge: 79+ (Latest ✅)

    Edge has full support for ES2020 features. You can use ES2020 features in Edge without any issues. Edge 79 and later versions fully support ES2020 features. Edge is a popular web browser, and it is recommended to test your JavaScript code in Edge to ensure compatibility.

  • Opera: 71+ (Latest ✅)

    Opera has full support for ES2020 features. You can use ES2020 features in Opera without any issues. Opera 71 and later versions fully support ES2020 features. Opera is a popular web browser, and it is recommended to test your JavaScript code in Opera to ensure compatibility.

  • Internet Explorer: No support (Latest ❌)

    Internet Explorer does not support ES2020 features. If you need to support Internet Explorer, you can use a transpiler like Babel to convert your ES2020 code into ES5 code, which is compatible with Internet Explorer.

Conclusion

ES2020 introduced several new features and enhancements to JavaScript, such as the BigInt primitive type, dynamic import() expressions, the nullish coalescing operator (??), the optional chaining operator (?.), and the Promise.allSettled() method. These features improve the expressiveness and flexibility of JavaScript, making it easier to write clean and concise code.