JavaScript Basic
What are the new features in ES6?
ES6 (ECMAScript 2015) Key Features
1. let and const
Block-scoped alternatives to var.
let count = 0;
const MAX = 100;
2. Arrow Functions
const add = (a, b) => a + b;
3. Template Literals
const name = 'Alice';
console.log(`Hello, ${name}!`);
4. Destructuring Assignment
const [a, b] = [1, 2];
const { name, age } = { name: 'Bob', age: 25 };
5. Default Parameters
function greet(name = 'World') {
return `Hello, ${name}!`;
}
6. Spread / Rest Syntax
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5]; // spread
function sum(...nums) { // rest
return nums.reduce((a, b) => a + b, 0);
}
7. Classes
class Animal {
constructor(name) { this.name = name; }
speak() { console.log(this.name); }
}
class Dog extends Animal {}
8. ES Modules
export const PI = 3.14;
export default function add(a, b) { return a + b; }
import add, { PI } from './math.js';
9. Promises
fetch('/api/data')
.then(res => res.json())
.catch(err => console.error(err));
10. Symbol
const id = Symbol('id');
11. Map and Set
const map = new Map();
const set = new Set([1, 2, 3]);
12. for...of Loop
for (const item of [1, 2, 3]) {
console.log(item);
}
13. Object Shorthand
const name = 'Alice';
const obj = { name, greet() { return 'hi'; } };
14. Iterators and Generators
function* gen() {
yield 1;
yield 2;
}
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
