Questions tagged [ecmascript-2021]

ECMAScript 2021 (ES2021) is the 12th version of the ECMAScript language. It adds new features including Promise.any, String#replaceAll, weak references and finalizers. Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2021.

ECMAScript 2021 (ES2021) is the 12th version of the language.

The following proposals have been merged:

ECMAScript 2021 Specification

16 questions
35
votes
1 answer

JavaScript String replace vs replaceAll

ECMAScript 2021 has added a new String function replaceAll. A long time ago in a galaxy not so far away, people used split + join or regular expressions to replace all occurences of a string. I created the following example to compare the new method…
Baptistou
  • 1,749
  • 1
  • 13
  • 24
9
votes
2 answers

Numeric literals with underscores in JavaScript

I recently ran into this code and i was wandering if there is any difference of writing those numeric literals in JavaScript with or without underscores: let number = 1234567890; console.log(number); let number2 =…
Ran Turner
  • 14,906
  • 5
  • 47
  • 53
6
votes
2 answers

What are WeakRef and finalizers in ES2021 (ES12)

I want to understand What are WeakRef and finalizers in ES2021 with a real simple example and Where to use them. I know, WeakRef is a class. This will allow developers to create weak references to objects, while a finalizer or FinalizationRegistry…
Abolfazl Roshanzamir
  • 12,730
  • 5
  • 63
  • 79
4
votes
1 answer

Read shadowed private field of the outer class

I expected that being inside of class B I can read private fields #a and #x of class A. But in fact I can read only #a, in case of access to #x I get an error: Cannot read private member #x from an object whose class did not declare it Seems like…
Qwertiy
  • 19,681
  • 15
  • 61
  • 128
3
votes
2 answers

What is the difference between a 'standard object' and an 'ordinary object' in ECMAScript?

Within the Terms and Definitions section of ECMAScript 2021 Language Specification, an ordinary object is defined as: object that has the default behaviour for the essential internal methods that must be supported by all objects A standard object…
pawooten
  • 140
  • 1
  • 9
3
votes
1 answer

Unexpected token "=" reported while running eslint on arrow functions

I have a JavaScript class and inside it I have an async method which looks like below. class ABC { func = async () => { //----line 10 //some code } func2 = () => { //----line 11 //some code } } When I run ESLint…
Naxi
  • 1,504
  • 5
  • 33
  • 72
3
votes
2 answers

Does top-level await have a timeout?

With top-level await accepted into ES2022, I wonder if it is save to assume that await import("./path/to/module") has no timeout at all. Here is what I’d like to do: // src/commands/do-a.mjs console.log("Doing a..."); await…
2
votes
2 answers

Flow does not support certain JavaScript (ECMAScript) built-in methods, what do I do?

As an embedded software engineer used to strictly-typed languages, I was compelled to use Flow (https://flow.org) when writing an experimental utility in JavaScript. About 10 minutes into writing code with JS+Flow, Flow ('flow-bin' binary) gave me…
MindMason
  • 23
  • 4
1
vote
1 answer

ES12: Nullish coalescing operators & objects

For example I have an object like this: const a = { b: "value" // and also what about: c: '', or c: 0, c: false ? }; And I'd like to assign a 'c', key to my object, but only if it's not assigned before. Usually we do something like this: if…
AlexZeDim
  • 3,520
  • 2
  • 28
  • 64
1
vote
1 answer

How to convert ECMAScript 12 to ECMAScript 10

I wrote a JS File, some of the codes in it are in ECMAScript 12. The problem is all my devices support only ECMAScript 10. This was the file Javascript Is there any online converters available, or how can I do it manually?
Random Kindle
  • 400
  • 1
  • 2
  • 12
0
votes
0 answers

Unit test fails because of static method

I encountered an interesting problem, there is such a service import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class TestService { static generate(url: string, response: string): string[] { return [url…
Joe Kappa
  • 39
  • 3
0
votes
0 answers

How to get missing ECMA script (es) version in nuxt project

So I have Nuxt project and I'm using node 16.16 version, And I would like to use https://yarnpkg.com/package/@tsconfig/node16#readme @tsconfig/node16 dependency that extends tsconfig.json. But after adding it I'v receive two error's TS6046: Argument…
hawk_lv
  • 23
  • 1
  • 5
0
votes
1 answer

"Running execution context" in await expression promise handlers abstract closure according to the Spec

I wanted to understand the internal mechanisms of a JavaScript engine for asynchronous functions, so I checked the Spec. For the rest of this question, I will refer to the linked version of the specification. Section 6.2.3.1 describes this.…
Stefan Octavian
  • 593
  • 6
  • 17
0
votes
1 answer

details.features.has is not a function

I am using angular 13 and es2021(also tried es6 to add 2018) tsconfig.lib.json ... "lib": ["dom", "es2021"] ... I have following object. export interface UserDetails { ... features?: Set; ... } I am trying to check some values…
mgnfcnt
  • 77
  • 11
0
votes
2 answers

I there an elegant way to re-assign deconstructed object values using ESNext

Lets say we have an object with some values const objectWithSomeValues = { numbers: 12345, word: 'hello', valueIDontWantToBeDeconstructed: [1,2,3,4,{}, null] } And somewhere else in the code I'm deconstructing this object const…
ColdHands
  • 947
  • 8
  • 28
1
2