8 Exciting New JavaScript Concepts You Need to Know

8 Exciting New JavaScript Concepts You Need to Know

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.

please subscribe to my YouTube channel to support my channel and get more web development tutorials.

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;
Enter fullscreen mode
Exit fullscreen mode

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';
Enter fullscreen mode
Exit fullscreen mode

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;
Enter fullscreen mode
Exit fullscreen mode

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
Enter fullscreen mode
Exit fullscreen mode

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);
}
Enter fullscreen mode
Exit fullscreen mode

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.

const promises = [Promise.resolve('a'), Promise.reject('b'), Promise.resolve('c')];
Promise.allSettled(promises).then((results) => console.log(results));
Enter fullscreen mode
Exit fullscreen mode

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.

const str = 'hello';
console.log(str.at(0)); // 'h'
console.log(str.at(-1)); // 'o'
Enter fullscreen mode
Exit fullscreen mode

8. Error Cause

A new property on Error objects, cause allows you to specify the underlying cause of an error.

try { throw new Error('Error occurred', { cause: new Error('Underlying cause') });
} catch (error) { console.log(error.cause);
}
Enter fullscreen mode
Exit fullscreen mode

Feel free to leave your comments or questions below. If you found this guide helpful, please share it with your peers and follow me for more web development tutorials. Happy coding!

Follow and Subscribe:


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *