In this tutorial, you will learn about the difference between ES5 and ES6. ES5 and ES6 are JavaScript versions.
What is ES5?
ES5 is the full form of ECMAScript 5, and it was released in 2009.
ES5 introduced some features like
- It has a strict mode
- It has JSON support.
- It has Array methods like map(), filter(), reduce().
Example of ES5 Function
function add(a, b) {
return a + b;
}
What is ES6?
ES6 (ECMAScript 2015) was released in 2015, and It has Modern JavaScript.
ES6 introduced many features
- let & const data types
- Arrow functions
- Classes
- Promises
- Modules
- Destructuring
Example of ES6 Function
const add = (a, b) => a + b;
ES5 vs ES6 – Quick Comparison Table
| Feature | ES5 | ES6 |
|---|---|---|
| Release year | 2009 | 2015 |
| Variable keywords | var | let, const |
| Functions | function | Arrow functions |
| Classes | ❌ No | ✅ Yes |
| Modules | ❌ No | ✅ import/export |
| Promises | ❌ No | ✅ Yes |
| Default params | ❌ No | ✅ Yes |
| Template strings | ❌ No | ✅ Yes |
Differences with Example
1. Use Variable
ES5
var name = "John";
ES6
let name = "John";
const age = 35;
2. Use Arrow Function
ES5
You use only the normal function in ES5
function welcome() {
console.log("Hello");
}
ES6
const welcome = () => {
console.log("Hello");
};
3. Use Template Literals
ES5
var name = "John";
var msg = "Hello " + name;
ES6
let name = "John";
const msg = `Hello ${name}`;
4. Use Classes
ES5
function Employee(name) {
this.name = name;
}
ES6
class Employee {
constructor(name) {
this.name = name;
}
}
5. Use Destructuring
ES5
var a = obj.a;
var b = obj.b;
ES6
const { a, b } = obj;
ES5 vs ES6 – Objective Questions (MCQs)
Q1. Which version introduced let and const?
Q2. Arrow functions were introduced in ______.
Q3. Which keyword is used for block-scoped variables in ES6?
Q4. Which feature is available in ES6 but NOT in ES5?
Q5. Which statement about ES6 modules is correct?