As a developer, staying up-to-date with the latest advancements in JavaScript is crucial to writing efficient, modern, and scalable code. In this post, we’ll explore 8 new and exciting JavaScript concepts that you should know to take your coding skills to the next level.
1. Optional Chaining (?.)
Introduced in ECMAScript 2020, optional chaining allows you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.
let name = person?.address?.street?.name;
2. Nullish Coalescing (??)
Also introduced in ECMAScript 2020, the nullish coalescing operator returns the first operand if it’s not null or undefined, and the second operand otherwise.
let name = person?.name?? 'Unknown';
3. BigInt
A new numeric primitive in JavaScript, BigInt is used to represent integers with arbitrary precision, allowing for accurate calculations with large integers.
const x = 12345678901234567890n;
4. globalThis
A new global object, globalThis, provides a way to access the global object in a way that’s compatible with modern JavaScript environments.
console.log(globalThis === window); // true in a browser
5. matchAll()
A new method on the String prototype, matchAll() returns an iterator that yields matches of a regular expression against a string, including capturing groups.
const regex = /(\w)(\d)/g;
const str = 'a1b2c3';
for (const match of str.matchAll(regex)) {
console.log(match);
}
6. Promise.allSettled()
A new method on the Promise API, allSettled() returns a promise that is resolved when all of the promises in an array are either resolved or rejected.
A new method on the String prototype, at() returns the character at the specified index, allowing for negative indices to access characters from the end of the string.
As a developer, staying up-to-date with the latest advancements in JavaScript is crucial to writing efficient, modern, and scalable code. In this post, we’ll explore 8 new and exciting JavaScript concepts that you should know to take your coding skills to the next level.
1. Optional Chaining (?.)
Introduced in ECMAScript 2020, optional chaining allows you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.
2. Nullish Coalescing (??)
Also introduced in ECMAScript 2020, the nullish coalescing operator returns the first operand if it’s not null or undefined, and the second operand otherwise.
3. BigInt
A new numeric primitive in JavaScript, BigInt is used to represent integers with arbitrary precision, allowing for accurate calculations with large integers.
4. globalThis
A new global object, globalThis, provides a way to access the global object in a way that’s compatible with modern JavaScript environments.
5. matchAll()
A new method on the String prototype, matchAll() returns an iterator that yields matches of a regular expression against a string, including capturing groups.
6. Promise.allSettled()
A new method on the Promise API, allSettled() returns a promise that is resolved when all of the promises in an array are either resolved or rejected.
7. String.prototype.at()
A new method on the String prototype, at() returns the character at the specified index, allowing for negative indices to access characters from the end of the string.
8. Error Cause
A new property on Error objects, cause allows you to specify the underlying cause of an error.
Author: Muhammad Talha Waseem
Recent Posts
Recent Posts
🚀 Successfully Integrated Stripe with Java for
Free Tools Every ML Beginner Should Use
Spring Modulith vs Microservices: Understanding the Differences
Archives