Features introduced in ES2021 ✨✨

ES2021 is slowly coming out in browsers. Here’s a
quick roundup of features provided by ES2021.

string.replaceAll (MDN)

Replaces all instances of a string.

‘xx’.replace(‘x’, ‘y’) //=> ‘yx’
‘xx’.replace(/x/g, ‘y’) //=> ‘yy’
‘xx’.repl…


This content originally appeared on DEV Community and was authored by Siddharth

ES2021 is slowly coming out in browsers. Here's a
quick roundup of features provided by ES2021.

string.replaceAll (MDN)

Replaces all instances of a string.

'xx'.replace('x', 'y') //=> 'yx'
'xx'.replace(/x/g, 'y') //=> 'yy'
'xx'.replaceAll('x', 'y') //=> 'yy'

Numeric separators (MDN)

Let's you seperate your numbers

const number = 1000000000; // Is this a billion? a hundred millions? Ten millions?
const number = 1_000_000_000; // Ah, so a billion

const FEE = 12300; // is this 12,300? Or 123, because it's in cents?
const FEE = 12_300; // $12,300 (woah, that fee!)

Logical OR assignment (||=) (MDN)

Logical OR assignment (foo ||= bar) assigns to foo if it is falsy.

let foo;
foo ||= 'bar';
foo; //=> 'bar'

foo ||= 'baz';
foo; //=> 'bar' (no assignment because foo is truthy)

Logical AND assignment (&&=) (MDN)

Logical AND assignment (foo &&= bar) assigns to foo if it is truthy.

let foo;
foo &&= 'bar';
foo; //=> undefined (no assignment because foo is falsy)

foo = 10;

foo &&= 'baz';
foo; //=> 'baz'

Logical nullish assignment (??=) (MDN)

Logical AND assignment (foo ??= bar) assigns to foo if it is nullish (null or undefined).

let foo;
foo ??= 'bar';
foo; //=> 'bar'

foo = false;

foo ??= 'baz';
foo; //=> 'bar' (No assignment because foo is not nullish)

Promise.any (MDN)

Basically Promise.race, but waits for resolvement instead of settlement.

WeakRef (MDN)

A WeakRef object lets you hold a weak reference to another object, without preventing that object from getting garbage-collected.

Support

You can check out details at CanIUse

Support is not too bad.

  • IE doesn't support any of these (but it doesn't matter).
  • Edge supports all of these from v85. Numeric separators are supported from v79, and WeakRef is supported from v84.
  • Firefox supports all of these from v79. Numeric separators are supported from v70, and String.replaceAll is supported from v77.
  • Chrome supports all of these from v85. Numeric separators are supported from v75, and WeakRef is supported from v84.
  • Opera supports Numeric separators from v62, and supports String.replaceAll from v71.
  • Safari on iOS supports all this from v14.7. Numeric separators are supported from v13, String.replaceAll is supported from v13.7, and Logical assignment and Promise.any are supported from v14.4
  • Android browser supports all this from v92
  • Opera Mobile supports String.replaceAll from v64
  • Chrome for Android supports all this from v92
  • Firefox for Android supports all this from v90
  • Samsung internet supports all this from v14.0. Numeric separators are supported from v11.1
  • Support on Opera Mini, QQ Browser, Baidu Browser, and KaiOS browser is unknown


This content originally appeared on DEV Community and was authored by Siddharth


Print Share Comment Cite Upload Translate Updates
APA

Siddharth | Sciencx (2021-08-02T07:31:37+00:00) Features introduced in ES2021 ✨✨. Retrieved from https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/

MLA
" » Features introduced in ES2021 ✨✨." Siddharth | Sciencx - Monday August 2, 2021, https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/
HARVARD
Siddharth | Sciencx Monday August 2, 2021 » Features introduced in ES2021 ✨✨., viewed ,<https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/>
VANCOUVER
Siddharth | Sciencx - » Features introduced in ES2021 ✨✨. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/
CHICAGO
" » Features introduced in ES2021 ✨✨." Siddharth | Sciencx - Accessed . https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/
IEEE
" » Features introduced in ES2021 ✨✨." Siddharth | Sciencx [Online]. Available: https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/. [Accessed: ]
rf:citation
» Features introduced in ES2021 ✨✨ | Siddharth | Sciencx | https://www.scien.cx/2021/08/02/features-introduced-in-es2021-%e2%9c%a8%e2%9c%a8/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.