ECMAScript 2020

  • Προηγούμενη σελίδα JS 2019
  • Επόμενη σελίδα JS 2021

JavaScript version number

Old JS versions are named by number: ES5 (2009) and ES6 (2015).

Starting from 2016, versions are named by year: ECMAScript 2016, 2017, 2018, 2019, ...

New features in ES2020:

Warning

These features are relatively new.

Older browsers may require alternative code (Polyfill).

BigInt in JavaScript

JavaScript BigInt variables are used to store large integer values that cannot be represented by ordinary JavaScript numbers.

JavaScript integers can only be precise up to 15 digits.

Integer instance

let x = 999999999999999;
let y = 9999999999999999; // Too large

Δοκιμάστε το προσωπικά

BigInt instance

let x = 9999999999999999;
let y = 9999999999999999n;

Δοκιμάστε το προσωπικά

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

Example

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

Δοκιμάστε το προσωπικά

The JavaScript type of BigInt is "bigint":

Example

let x = BigInt(999999999999999);
let type = typeof x;

Δοκιμάστε το προσωπικά

Since September 2020, all modern browsers support BigInt:

Chrome Edge Firefox Safari Opera
Chrome 67 Edge 79 Firefox 68 Safari 14 Opera 54
May 2018 January 2020 July 2019 Σεπτέμβριος 2020 June 2018

Μέθοδος matchAll() για字符串

Before ES2020, there were no string methods available to search for all occurrences of a string in a string.

Example

const iterator = text.matchAll("Cats");

Δοκιμάστε το προσωπικά

If the parameter is a regular expression, you must set the global flag (g) or it will throw a TypeError.

Example

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

Δοκιμάστε το προσωπικά

If you want to perform a case-insensitive search, you must set the case-insensitive flag (i)

Example

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

Δοκιμάστε το προσωπικά

Hint:ES2021 The string method replaceAll() was introduced.

Nullish Coalescing Operator (Nullish Coalescing Operator) (?? Operator)

If the first parameter is not a null value (null or undefinedthen ?? The operator returns the first parameter.

otherwise return the second.

Example

let name = null;
let text = "missing";
let result = name ?? text;

Δοκιμάστε το προσωπικά

Since March 2020, all modern browsers have supported nullish operators:

Chrome Edge Firefox Safari Opera
Chrome 80 Edge 80 Firefox 72 Safari 13.1 Opera 67
February 2020 February 2020 January 2020 Μάρτιος 2020 Μάρτιος 2020

Optional Chaining Operator (Optional Chaining Operator) (?. Operator)

If the object is undefined or nullthenOptional Chaining OperatorReturns undefined(instead of throwing an error).

Example

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

Δοκιμάστε το προσωπικά

Since March 2020, all modern browsers have supported ?.= Αντιγραφές:

Chrome Edge Firefox Safari Opera
Chrome 80 Edge 80 Firefox 74 Safari 13.1 Opera 67
February 2020 February 2020 Μάρτιος 2020 Μάρτιος 2020 Μάρτιος 2020

Λογικός AND όρισμα αποθήκευσης (&&= όρισμα)

Logical AND Assignment Operatorused between two values.

If the first value is trueΑν δεν είναι διαθέσιμος ο πρώτος όρος, τότε θα αποθηκευτεί ο δεύτερος όρος.

Logical AND Assignment Example

let x = 100;
x &&= 5;

Δοκιμάστε το προσωπικά

Από τον Σεπτέμβριο του 2020, όλα τα σύγχρονα προγράμματα περιήγησης υποστηρίζουν &&= Αντιγραφές:

Chrome Edge Firefox Safari Opera
Chrome 85 Edge 85 Firefox 79 Safari 14 Opera 71
Αύγουστος 2020 Αύγουστος 2020 Μάρτιος 2020 Σεπτέμβριος 2020 Σεπτέμβριος 2020

Logical OR Assignment Operator (||= Operator)

Logical OR Assignment Operatorused between two values.

If the first value is falseΑν δεν είναι διαθέσιμος ο πρώτος όρος, τότε θα αποθηκευτεί ο δεύτερος όρος.

Logical OR Assignment Example

let x = 10;
x ||= 5;

Δοκιμάστε το προσωπικά

Από τον Σεπτέμβριο του 2020, όλα τα σύγχρονα προγράμματα περιήγησης υποστηρίζουν ||= Αντιγραφές:

Chrome Edge Firefox Safari Opera
Chrome 85 Edge 85 Firefox 79 Safari 14 Opera 71
Αύγουστος 2020 Αύγουστος 2020 Μάρτιος 2020 Σεπτέμβριος 2020 Σεπτέμβριος 2020

Σύμπλοκο όρισμα αποθήκευσης (??= όρισμα)

Σύμπλοκο όρισμα αποθήκευσης(Nullish Coalescing Assignment Operator)χρησιμοποιείται μεταξύ δύο τιμών.

Αν ο πρώτος όρος undefined ή nullΑν δεν είναι διαθέσιμος ο πρώτος όρος, τότε θα αποθηκευτεί ο δεύτερος όρος.

Παράδειγμα συμπλοκού όρισμα αποθήκευσης

let x = 10;
x ??= 5;

Δοκιμάστε το προσωπικά

Από τον Σεπτέμβριο του 2020, όλα τα σύγχρονα προγράμματα περιήγησης υποστηρίζουν ??= Αντιγραφές:

Chrome Edge Firefox Safari Opera
Chrome 85 Edge 85 Firefox 79 Safari 14 Opera 71
Αύγουστος 2020 Αύγουστος 2020 Μάρτιος 2020 Σεπτέμβριος 2020 Σεπτέμβριος 2020
  • Προηγούμενη σελίδα JS 2019
  • Επόμενη σελίδα JS 2021