ES6 Features

 ES6 Features


ECMAScript 6 (ES6) introduced many new features to JavaScript, including arrow functions, template literals, destructuring, and classes.


Here is an example of using arrow functions:


javascript

Copy code

const numbers = [1, 2, 3, 4, 5];


const evenNumbers = numbers.filter(n => n % 2 === 0);


console.log(evenNumbers); // [2, 4]

In this example, we use an arrow function to filter even numbers from an array.


Here is an example of using destructuring:



const user = {

  id: 1,

  username: 'johnDoe',

  email: 'johnDoe@example.com'

};


const { id, email } = user;


console.log(id); // 1

console.log(email); // 'johnDoe@example.com'

In this example, we use destructuring to extract the id and email properties from a user object.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...