let allows you to declare block-scoped variables, which is safer than var.
let count = 10;
count = 15; // allowed
const PI = 3.14;
// PI = 3.5 ❌ Error
Use const by default, and let only when reassignment is needed.
function add(a, b) {
return a + b;
}
const add = (a, b) => a + b;
const numbers = [1, 2, 3];
const newNumbers = [...numbers, 4, 5];
const user = { name: "John" };
const details = { age: 25 };
const fullUser = { ...user, ...details };
const numbers = [1, 2, 3, 4];
const squared = numbers.map(num => num * num);
[1, 4, 9, 16]
const ages = [12, 18, 25, 14];
const adults = ages.filter(age => age >= 18);
| Method | Purpose | Returns |
|---|---|---|
| map() | Transform data | New array (same length) |
| filter() | Filter data | New array (filtered) |
| Feature | ES5 | ES6 (ES2015) |
|---|---|---|
| Variable Declaration | var |
let, const |
| Function Syntax | Traditional functions | Arrow functions () => {} |
| Scope | Function scope | Block scope |
| String Handling | String concatenation | Template literals `Hello ${name}` |
| Default Parameters | Not supported | Supported |
| Array Methods | Limited | map(), filter(), reduce() |
| Object Handling | Manual assignments | Destructuring, spread operator |
| Modules | Not supported | import / export |
| Classes | Prototype-based | class syntax |
| Readability | More verbose | Cleaner and concise |