Features Introduced in JavaScript ES6 (ECMAScript 2015):
🔹 1. let and const
letfor block-scoped variables.constfor constants (block-scoped & cannot be reassigned).
let name = "Teekam";
const age = 25;
🔹 2. Arrow Functions
- Shorter syntax for function expressions.
- Lexically binds
this.
const greet = () => console.log("Hello!");
🔹 3. Template Literals
- Embed expressions using backticks and
${}.
let msg = `Hello, ${name}!`;
🔹 4. Default Parameters
- Set default values for function parameters.
function greet(user = "Guest") {
console.log(`Hello, ${user}`);
}
🔹 5. Destructuring Assignment
- Extract values from arrays or objects.
const [a, b] = [1, 2];
const { name, age } = { name: "Teekam", age: 25 };
🔹 6. Rest and Spread Operators
- Rest
...collects items into an array. - Spread
...expands elements.
function sum(...nums) { return nums.reduce((a, b) => a + b); }
const arr = [1, 2];
const newArr = [...arr, 3];
🔹 7. Classes
- Syntactic sugar over constructor functions.
class Person {
constructor(name) {
this.name = name;
}
}
🔹 8. Modules (import/export)
- For modular, reusable code.
export const add = (a, b) => a + b;
import { add } from './math.js';
🔹 9. Promises
- Handle async operations more cleanly.
fetch(url)
.then(res => res.json())
.then(data => console.log(data));
🔹 10. Enhanced Object Literals
- Shorthand for methods and properties.
let name = "Teekam";
let user = {
name,
greet() { console.log("Hi"); }
};
🔹 11. For...of Loop
- Iterates over iterable objects like arrays.
for (let val of [1, 2, 3]) {
console.log(val);
}
📝 In Summary:
ES6 introduced major features like let/const, arrow functions, classes, promises, template literals, modules, destructuring, and more—making JavaScript more powerful and readable.