ES2022 Features

Javascript keeps on evolving and the new syntaxes has been followed in ES2022. Some of them are 👇

1) Private Class fields

In olders ways we can make a class variable as private. We use the # to determine that it is private.

class Hello {
name = …


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

Javascript keeps on evolving and the new syntaxes has been followed in ES2022. Some of them are 👇

1) Private Class fields

In olders ways we can make a class variable as private. We use the # to determine that it is private.

class Hello {
name = "Dhanush",
#work ="Engineer"
}

console.log(Hello.name) // Prints "Dhanush"
console.log(Hello.#work) // Cannot be read from outside

2) Top Level Await

We can do a await call directly in a javascript file, without defining an asynchronous function

await db.collection();

Previously

async function result(){
await db.collection();
}

await result()

Top level await works only when the script type is module

3) Accessing arrays

The at method for accessing array elements, which also helps to access elements from the last by providing negative indices

`const array = [1,2,3,4,5]

array.at(2) // 2
array.at(-1) // 5`

4) Object.hasOwn

Used to find whether the property exists in an object

Syntax: Object.hasOwn(<object>, <object_property>)

5) Regex Indices

New feature in regex which adds a d flag in regex expression

In the output you would get an array of indices, which contains the starting point to the ending point of where the keyword is found in the regular expression match.

Any inputs or additions feel free to add below 👇

For more insights & tech lets stay connected via Twitter


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


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-03-06T18:57:46+00:00) ES2022 Features. Retrieved from https://www.scien.cx/2022/03/06/es2022-features/

MLA
" » ES2022 Features." DEV Community | Sciencx - Sunday March 6, 2022, https://www.scien.cx/2022/03/06/es2022-features/
HARVARD
DEV Community | Sciencx Sunday March 6, 2022 » ES2022 Features., viewed ,<https://www.scien.cx/2022/03/06/es2022-features/>
VANCOUVER
DEV Community | Sciencx - » ES2022 Features. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/06/es2022-features/
CHICAGO
" » ES2022 Features." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/03/06/es2022-features/
IEEE
" » ES2022 Features." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/03/06/es2022-features/. [Accessed: ]
rf:citation
» ES2022 Features | DEV Community | Sciencx | https://www.scien.cx/2022/03/06/es2022-features/ |

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.