Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Let JS Const JS Types

JS Operators

JS Operators JS Arithmetic JS Assignment JS Comparisons JS Conditional JS If JS If Else JS Ternary JS Switch JS Booleans JS Logical

JS Loops

JS Loops JS Loop for JS Loop while JS Break JS Continue JS Control Flow

JS Strings

JS Strings JS String Templates JS String Methods JS String Search JS String Reference

JS Numbers

JS Numbers JS Number Methods JS Number Properties JS Number Reference JS Bitwise JS BigInt

JS Functions

Function Path Function Intro Function Invocation Function Parameters Function Returns Function Arguments Function Expressions Function Arrow Function Quiz

JS Objects

Object Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors

JS Scope

JS Scope JS Code Blocks JS Hoisting JS Strict Mode

JS Dates

JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods

JS Arrays

JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const

JS Sets

JS Sets JS Set Methods JS Set Logic JS Set WeakSet JS Set Reference

JS Maps

JS Maps JS Map Methods JS Map WeakMap JS Map Reference

JS Iterations

JS Loops JS Iterables JS Iterators JS Generators

JS Math

JS Math JS Math Reference JS Math Random

JS RexExp

JS RegExp JS RegExp Flags JS RegExp Classes JS RegExp Metachars JS RegExp Assertions JS RegExp Quantifiers JS RegExp Patterns JS RegExp Objects JS RegExp Methods

JS Data Types

JS Destructuring JS Data Types JS Primitive Data JS Object Types JS typeof JS toString JS Type Conversion

JS Errors

JS Errors Intro JS Errors Silent JS Error Statements JS Error Object

JS Debugging

Debugging Intro Debugging Console Debugging Breakpoints Debugging Errors Debugging Async Debugging Reference

JS Conventions

JS Style Guide JS Best Practices JS Mistakes JS Performance

JS References

JS Statements JS Reserved Keywords JS Operators JS Precedence

JS Versions

JS 2026 JS 2025 JS 2024 JS 2023 JS 2022 JS 2021 JS 2020 JS 2019 JS 2018 JS 2017 JS 2016 JS Versions JS 2015 (ES6) JS 2009 (ES5) JS 1999 (ES3) JS IE / Edge JS History

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Temporal  New JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


ECMAScript 2020


New Features in JavaScript 2020

FeatureDescription
BigInt Stores values too big to store in a JavaScript number
String matchAll() Searchs for all occurrences of a string in a string
Promise.allSettled() Takes promises as input and returns a single promise
Dynamic Import Loads JavaScript modules at runtime
globalThis Refers to the global object independent of code environment
import.meta Returns an object indicating the base URL of a module
Namespace Exports Export a full namespace from a module without having to import it first

New JavaScript Operators in 2020

OperDescription
?? Nullish coalescing returns the first argument not nullish
?. Optional chaining returns undefined if an object is undefined or null
&&= Logical AND assignment assigns the second value if the first value is true
||= Logical OR assignment assigns the second value if the first value is false
??= Nullish coalescing assignment assigns the second value if the first value is undefined or null

Browser Support

ECMAScript 2020 is supported in all modern browsers since April 2021.

Chrome
80
Edge
80
Firefox
80
Safari
14.1
Opera
67
Feb 2020 Feb 2020 Aug 2020 Apr 2021 Mar 2020

JavaScript BigInt

JavaScript BigInt variables are used to store big integer values that are too big to be represented by a a normal JavaScript Number.

JavaScript integers are only accurate up to about 15 digits.

Integer Example

let x = 999999999999999;
let y = 9999999999999999; // too big
Try it Yourself »

BigInt Example

let x = 9999999999999999;
let y = 9999999999999999n;
Try it Yourself »

To create a BigInt, append n to the end of an integer or call BigInt():

Example

let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)
Try it Yourself »

The JavaScript typeof a BigInt is "bigint":

Example

let x = BigInt(999999999999999);
let type = typeof x;
Try it Yourself »

JavaScript String matchAll()

Before ES2020 there was no string method that could be used to search for all occurrences of a string in a string.

Example

const iterator = text.matchAll("Cats");
Try it Yourself »

If the parameter is a regular expression, the global flag (g) must be set set, otherwise a TypeError is thrown.

Example

const iterator = text.matchAll(/Cats/g);
Try it Yourself »

If you want to search case insensitive, the insensitive flag (i) must be set:

Example

const iterator = text.matchAll(/Cats/gi);
Try it Yourself »

Note

ES2021 introduced the string method replaceAll().



The Nullish Coalescing Operator (??)

The ?? operator returns the first operand if it is not nullish. Otherwise it returns the second.

The ?? operator returns the second operand if the first operand is nullish.

Nullish is a word for describing null or undefined.

The ?? operator is used to provide default values and is distinct from the logical OR operator || because it only treats null and undefined as "nullish" and ignores other "falsy" values like 0 or an empty string.

Example

let name = null;
let text = "missing";
let result = name ?? text;
Try it Yourself »

The Optional Chaining Operator (?.)

The Optional Chaining Operator returns undefined if an object property is undefined or null (instead of throwing an error).

Example

const car = {type:"Fiat", model:"500", color:"white"};
let name = car?.name;
Try it Yourself »

Optional chaining not only works on object properties, but also on function calls and arrays.

Function Calls

Use CaseSyntaxBehavior
Safe function callobj.method?.() Returns undefined if method does not exist
Return handlinglet x = fn?.()x is undefined if fn does not exist

Arrays

Use CaseSyntaxReturns
Safe element accessarr?.[2] undefined if arr is null or undefined
Safe property on elementarr?.[1]?.name Returns undefined safely
Safe method callarr?.map(fn) Returns undefined if arr does not exist
Default value fallbackarr?.[0] ?? "N/A" Returns "N/A" if arr or element is missing

The &&= Operator

The Logical AND Assignment Operator is used between two values.

If the first value is true, the second value is assigned.

Logical AND Assignment Example

let x = 10;
x &&= 5;
Try it Yourself »

The ||= Operator

The Logical OR Assignment Operator is used between two values.

If the first value is false, the second value is assigned.

Logical OR Assignment Example

let x = 10;
x ||= 5;
Try it Yourself »

The ??= Operator

The Nullish Coalescing Assignment Operator is used between two values.

If the first value is undefined or null, the second value is assigned.

Nullish Coalescing Assignment Example

let x;
x ??= 10;
Try it Yourself »

JavaScript Promise.allSettled()

The Promise.allSettled() method returns a single Promise from a list of promises.

Example

// Create a Promise
const myPromise1 = new Promise((resolve, reject) => {
  setTimeout(resolve, 200, "King");
});

// Create another Promise
const myPromise2 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, "Queen");
});

// Settle All
Promise.allSettled([myPromise1, myPromise2]).then((results) =>
  results.forEach((x) => myDisplay(x.status)),
);
Try it Yourself »

Note

Promise.allSettled() means "Just run all promises. I don't care about the results".


JavaScript Dynamic Import

Dynamic Import is a way to load JavaScript modules at runtime, rather than at the start of your program.

Syntax

import("./module.js")
  • The argument must be a string or expression that resolves to a path
  • You must run the import inside a module script (<script type="module">)

Unlike static imports (which must appear at the top of a file), dynamic imports can be used anywhere - inside functions, conditionals, event handlers, etc.

TypeExampleWhen Loaded
Staticimport { add } from './math.js'; At load time
Dynamicconst math = await import('./math.js'); When needed

JavaScript Global This

globalThis provides a standard way to access the global object, regardless of the environment your the code runs in: In the browser, Node.js, in a Web Worker, or another JS runtime.

The global object is the top-level object in a JavaScript environment:

  • In browsers, it is window.
  • In Node.js, it is global.
  • In Web Workers, it is self.

Many environments have their own name for the this object. This caused compatibility issues for code meant to run everywhere.

globalThis was introduced in ECMAScript 2020 (ES11) to solve that problem. It is a unified reference to the global object, no matter the environment.

Examples

globalThis === window); // true in browsers
globalThis === global); // true in Node.js
Try it Yourself »

Example

Defining a truly global variable:

globalThis.appName = "W3Schools Demo";
Try it Yourself »

Previously, developers had to use workarounds like:

Example

const getGlobal = function() {
  if (typeof self !== 'undefined') return self;
  if (typeof window !== 'undefined') return window;
  if (typeof global !== 'undefined') return global;
  throw new Error('Cannot find global object');
};

With globalThis, that is no longer needed.


JavaScript import.meta

import.meta returns an object containing the base URL of a module.

Example

const myObject = import.meta;
Try it Yourself »

Module Namespace Exports

With module namespace exports, you can re-export an entire namespace from your own module, without having to import it first.

Example

Before:

// re-export all named exports directly
export * from "./utils.js";
// consumers can use:
import { add } from "./math.js";

Now:

// re-export all as a namespace
export * as utils from "./utils.js";
// consumers can use:
import { utils } from "./math.js";

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->