ES2022 is gonna be OP.

ECMAScript 2022 is the new JavaScript standard that is going to be released in June 2022. Let’s overview the most important changes that would appear almost certainly in the new release as they reached the 4th stage of TC39 process.

1. .a…


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

ECMAscript2022

ECMAScript 2022 is the new JavaScript standard that is going to be released in June 2022. Let’s overview the most important changes that would appear almost certainly in the new release as they reached the 4th stage of TC39 process.

1. .at() method in arrays

Finally! ES2022 will give us a possibility to index array-like objects from the end. That’s a tiny feature, but it improves core readability when dealing with arrays or strings.

before

const array = [1, 2, 3, 4]
array[array.length - 2] // 3
array.slice(-2)[0]    // 3

const string = "1234"
string[string.length - 2] // '3'
string.slice(-2)[0]    // '3'

after

const array = [1, 2, 3, 4]
array.at(-2) // 3

const string= "1234"
string.at(-2) // '3'

2. Error Cause

.cause property on the error object would allow us to specify which error caused the other error. Here you can see an example use of this new feature ->

try {
  doSomethingThatWillThrowAnError() 
} catch (error) {
  throw new Error('I am the result of another error', { cause: error })
}

I couldn’t find any information whether stack trace of error included in cause would be present in the thrown error. Let me know if you find any information about that.

3. Top-level async/await

Now, in ECMAscript 2022, you can do this shit ->

const moduleName = await fetch("https://example.com/some/random/module")
const service = await import(`/dist/modules/${moduleName}.js`)

// --------------
// ----- OR -----
// --------------

const date = new Date()

if(date.getFullYear() === 2022) {
  await require('/newcode-2022-only.js')
} else {
  await require('/legacy-code.js');
}


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


Print Share Comment Cite Upload Translate Updates
APA

Akash Pattanaik | Sciencx (2022-02-04T07:56:35+00:00) ES2022 is gonna be OP.. Retrieved from https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/

MLA
" » ES2022 is gonna be OP.." Akash Pattanaik | Sciencx - Friday February 4, 2022, https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/
HARVARD
Akash Pattanaik | Sciencx Friday February 4, 2022 » ES2022 is gonna be OP.., viewed ,<https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/>
VANCOUVER
Akash Pattanaik | Sciencx - » ES2022 is gonna be OP.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/
CHICAGO
" » ES2022 is gonna be OP.." Akash Pattanaik | Sciencx - Accessed . https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/
IEEE
" » ES2022 is gonna be OP.." Akash Pattanaik | Sciencx [Online]. Available: https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/. [Accessed: ]
rf:citation
» ES2022 is gonna be OP. | Akash Pattanaik | Sciencx | https://www.scien.cx/2022/02/04/es2022-is-gonna-be-op/ |

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.