Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS 2020

JavaScript Version Numbers

Earlier ECMAScript versions were named by numbers, such as ES5 and ES6. Starting in 2016, versions are named after their release year, like ES2016, ES2018, ES2020, and so on.

New Features in ES2020

  • BigInt
  • String matchAll()
  • The Nullish Coalescing Operator (??)
  • The Optional Chaining Operator (?.)
  • Logical AND Assignment Operator (&&=)
  • Logical OR Assignment (||=)
  • Nullish Coalescing Assignment (??=)
  • Promise.allSettled()
  • Dynamic Import
Warning:
These features are relatively new, so older browsers may require alternative code or a polyfill for compatibility.

JavaScript BigInt

JavaScript BigInt variables are used to store integer values that exceed the size limit of regular JavaScript Number values. JavaScript integers are only precise up to about 15 digits.

Integer Example

let x = 999999999999999;
let y = 9999999999999999// too big

BigInt Example

let x = 9999999999999999;
let y = 9999999999999999n;

To create a BigInt, either append n to the end of an integer or use the BigInt() constructor.

Example

let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)

The typeof a BigInt in JavaScript is “bigint”.

Example

let x = 1234567890123456789012345n;
let y = BigInt(1234567890123456789012345)

js 3

JavaScript String matchAll()

Prior to ES2020, there was no string method available to find all instances of a substring within a string.

Example

const iterator = text.matchAll(“Cats”);

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

Example

const iterator = text.matchAll(/Cats/g);

To perform a case-insensitive search, the “i” flag must be applied.

Example

const iterator = text.matchAll(/Cats/gi);

The Nullish Coalescing Operator (??)

The ?? operator returns the first argument if it is not null or undefined; otherwise, it returns the second argument.

Example

let name = null;
let text = “missing”;
let result = name ?? text;

All modern browsers have supported the nullish coalescing operator since March 2020.

js 5