8 Exciting New JavaScript Concepts You Need to Know
Tags: javascript, webdev, beginners, learning
Published: 2024-07-09 16:32:50

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](https://www.youtube.com/@DevDivewithDipak?sub_confirmation=1
) 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.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
const promises = [Promise.resolve('a'), Promise.reject('b'), Promise.resolve('c')];
Promise.allSettled(promises).then((results) => console.log(results));
```

**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.

```javascript
const str = 'hello';
console.log(str.at(0)); // 'h'
console.log(str.at(-1)); // 'o'
```

**8. Error Cause**

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

```javascript
try {
  throw new Error('Error occurred', { cause: new Error('Underlying cause') });
} catch (error) {
  console.log(error.cause);
}
```

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:
- **Website**: [Dipak Ahirav] (https://www.dipakahirav.com)
- **Email**: dipaksahirav@gmail.com
- **Instagram**: [devdivewithdipak](https://www.instagram.com/devdivewithdipak)
- **YouTube**: [devDive with Dipak](https://www.youtube.com/@DevDivewithDipak?sub_confirmation=1
)
- **LinkedIn**: [Dipak Ahirav](https://www.linkedin.com/in/dipak-ahirav-606bba128)