Modern JavaScript Features
ES6 (ES2015) and later versions introduced powerful features that make JavaScript more expressive and easier to work with.
Arrow Functions
Arrow functions provide a shorter syntax and lexical this binding:
const add = (a, b) => a + b;
Template Literals
Template literals allow embedded expressions and multi-line strings:
const message = `Hello, ${name}!`;
Destructuring
Extract values from arrays and objects more easily:
const { name, age } = user;
const [first, second] = array;
Spread and Rest Operators
The spread operator (...) expands iterables, while rest collects them:
const newArray = [...oldArray, newItem];
const sum = (...numbers) => numbers.reduce((a, b) => a + b);
Promises and Async/Await
Handle asynchronous operations more elegantly:
async function fetchData() {
const response = await fetch('/api/data');
return response.json();
}
Modules
Organize code with import and export statements:
import { Component } from 'react';
export default MyComponent;
Classes
ES6 classes provide a cleaner syntax for object-oriented programming in JavaScript.