Features and Methods of JavaScript ES5 (2009)

Last Updated : 10 Oct, 2026

ECMAScript 5 (ES5), released in December 2009, introduced several improvements to JavaScript, making code more reliable and easier to maintain.

  • Improved error handling and coding practices while adding methods for working with arrays and strings.
  • Introduced native JSON support and enhanced date handling and serialization.
  • Provided greater control over object properties and behavior through new object methods.

1. Strict Mode ("use strict")

Strict mode (use strict) enables stricter parsing and error handling in JavaScript. It helps detect common mistakes, such as assigning a value to an undeclared variable.

Syntax:

"use strict";

// Strict mode applies to this script.

Example:

JavaScript
"use strict";

function strictFunction(a, b) {
    result = a + b;
    return result;
}

console.log(strictFunction(5, 10));

Output

ReferenceError: result is not defined

2. String.prototype.trim()

The trim() method removes whitespace from the beginning and end of a string without modifying the original string.

Syntax:

string.trim();

Example:

JavaScript
var str = "   GeeksforGeeks   ";
var result = str.trim();

console.log(result);

Output
GeeksforGeeks

3. Multiline Strings

ES5 does not support template literals. A string can continue across source lines using a backslash immediately followed by a line terminator. The line break is not included in the resulting string. String concatenation is often clearer.

Example:

JavaScript
var str = "GeeksforGeeks " +
          "is a computer science " +
          "portal.";

console.log(str);

Output
GeeksforGeeks is a computer science portal.

4. Array Methods

ES5 introduced several array methods that simplify array iteration, transformation, filtering, and value checking.

  • Array.isArray(): Checks whether a value is an array.
  • forEach(): Executes a callback for each array element.
  • map(): Creates a new array from callback results.
  • filter(): Returns a new array containing elements that pass a test.
  • reduce() and reduceRight(): Combine array elements into a single result.
  • every() and some(): Check whether all or at least one element satisfies a condition.
  • indexOf() and lastIndexOf(): Find the first or last occurrence of a value.

Example:

JavaScript
var numbers = [1, 2, 3, 4, 5];

console.log(Array.isArray(numbers));

var doubled = numbers.map(function (number) {
    return number * 2;
});

var evenNumbers = numbers.filter(function (number) {
    return number % 2 === 0;
});

var sum = numbers.reduce(function (total, number) {
    return total + number;
}, 0);

console.log(doubled);
console.log(evenNumbers);
console.log(sum);

Output
true
[ 2, 4, 6, 8, 10 ]
[ 2, 4 ]
15

5. JSON.parse()

The JSON.parse() method converts a valid JSON string into a JavaScript value, such as an object or array. It also supports an optional reviver function to transform parsed values.

Syntax:

JSON.parse(text, reviver);

Example:

JavaScript
var jsonString = '{"name":"Alen","age":21,"city":"Noida"}';

var result = JSON.parse(jsonString);

console.log(result.name);
console.log(result.age);
console.log(result.city);

Output
Alen
21
Noida

6. JSON.stringify()

The JSON.stringify() method converts a JavaScript value into a JSON string. It supports optional arguments for filtering properties and formatting the output.

Syntax:

JSON.stringify(value, replacer, space);

Example:

JavaScript
var person = {
    name: "GeeksforGeeks",
    established: 2009,
    location: "Noida"
};

var result = JSON.stringify(person);

console.log(result);

Output
{"name":"GeeksforGeeks","established":2009,"location":"Noida"}

7. Date Methods

ES5 introduced date methods that simplify timestamp retrieval and standardized date serialization.

  • Date.now(): Returns milliseconds elapsed since January 1, 1970, UTC.
  • toISOString(): Converts a date to an ISO 8601 string in UTC.
  • toJSON(): Returns the ISO-formatted string for a valid date object.

Example:

JavaScript
var currentDate = new Date();

console.log("Timestamp:", Date.now());
console.log("ISO String:", currentDate.toISOString());
console.log("JSON Date:", currentDate.toJSON());

Output
Timestamp: 1791625049488
ISO String: 2026-10-10T09:37:29.488Z
JSON Date: 2026-10-10T09:37:29.488Z

Note: The timestamp and date strings vary depending on when the code runs.

8. Property Getters and Setters

ES5 supports getters and setters in object literals. A getter defines behavior when a property is read, while a setter defines behavior when a property is assigned a value.

Example:

JavaScript
var person = {
    firstName: "John",
    lastName: "Doe",

    get fullName() {
        return this.firstName + " " + this.lastName;
    },

    set fullName(name) {
        var parts = name.split(" ");
        this.firstName = parts[0];
        this.lastName = parts[1];
    }
};

console.log(person.fullName);

person.fullName = "Jane Smith";

console.log(person.firstName);
console.log(person.lastName);

Output
John Doe
Jane
Smith

9. Object Property Methods

ES5 introduced methods for defining property attributes, inspecting properties, and controlling whether objects can be extended or modified.

Method

Description

Object.defineProperty()

Defines or modifies a property's attributes.

Object.defineProperties()

Defines multiple properties on an object.

Object.getOwnPropertyDescriptor()

Returns the descriptor of an own property.

Object.keys()

Returns an array of an object's own enumerable string-keyed property names.

Object.getOwnPropertyNames()

Returns all own string-keyed property names, including non-enumerable ones.

Object.preventExtensions()

Prevents adding new properties to an object.

Object.isExtensible()

Checks whether an object can be extended.

Object.seal()

Prevents adding or removing properties and makes existing properties non-configurable.

Object.isSealed()

Checks whether an object is sealed.

Object.freeze()

Prevents adding or removing properties and changing existing data properties.

Object.isFrozen()

Checks whether an object is frozen.

Example:

JavaScript
var person = {};

Object.defineProperty(person, "name", {
    value: "Alen",
    writable: false,
    enumerable: true,
    configurable: false
});

Object.defineProperties(person, {
    age: {
        value: 21,
        writable: true,
        enumerable: true,
        configurable: true
    },
    city: {
        value: "Delhi",
        writable: true,
        enumerable: true,
        configurable: true
    }
});

console.log(Object.keys(person));
console.log(Object.getOwnPropertyNames(person));

Object.preventExtensions(person);
console.log(Object.isExtensible(person));

Object.seal(person);
console.log(Object.isSealed(person));

Object.freeze(person);
console.log(Object.isFrozen(person));

console.log(person);

Output
[ 'name', 'age', 'city' ]
[ 'name', 'age', 'city' ]
false
true
true
{ name: 'Alen', age: 21, city: 'Delhi' }
Comment