ECMAScript 5 (ES5) was released in 2009 and brought several important features to JavaScript. It was widely adopted and is supported by all modern browsers.
Key Features
- Strict Mode: Introduced
"use strict"
to enforce stricter parsing and error handling. - JSON Support: Added native JSON parsing with
JSON.parse()
andJSON.stringify()
. - Array Methods: Introduced new array methods like
forEach()
,map()
,filter()
,reduce()
, andsome()
. - Object Methods: Added
Object.create()
,Object.keys()
,Object.defineProperty()
, and others for better object manipulation. - Function Binding: Introduced the
bind()
method for explicitly setting thethis
value in function calls. - Property Attributes: Allowed defining property attributes like writable, enumerable, and configurable.
Example
"use strict";
// Using new array methods
let numbers = [1, 2, 3, 4, 5];
let doubled = numbers.map(num => num * 2);
console.log(doubled); // [2, 4, 6, 8, 10]
// Object manipulation
let person = Object.create(null);
Object.defineProperty(person, 'name', {
value: 'John',
writable: false,
enumerable: true
});
console.log(person.name); // "John"
person.name = 'Jane'; // This won't change the name due to writable: false
console.log(person.name); // Still "John"
ES5 laid the foundation for modern JavaScript development and is still widely used today.