Back to JavaScript Notes
Topic #437

ES5

You will be able to write and read JavaScript that runs in ES5 environments by using var, function expressions, prototypes, and ES5 array methods.

What it is

ES5 is the fifth edition of ECMAScript, the standard behind JavaScript. It is the baseline many older codebases still target because it works in older browsers and simple JavaScript engines without a build step. The mental model is: variables are function-scoped, functions are ordinary values, objects are built with constructors and prototypes, and modern syntax such as arrow functions, classes, and block-scoped variables is not available. Related terms include strict mode, IIFE, polyfill, transpilation, ES3, and ES6 or ES2015.

Why it matters

  • It lets you maintain legacy applications that still run in older browsers.
  • It helps you understand code generated by transpilers such as Babel.
  • It is useful in embedded JavaScript environments where only ES5 is supported.
  • It teaches core JavaScript ideas like function scope, callbacks, and prototypes.
  • It reduces surprises when reading older libraries or interview examples.

Syntax or steps

The smallest useful ES5 pattern is strict mode, var, function expressions, and ES5 array methods.

  1. Start with "use strict"; to catch common mistakes.
  2. Declare variables with var.
  3. Create functions with function expressions instead of arrow functions.
  4. Use prototypes for shared object behavior.
  5. Use ES5 methods such as forEach, map, filter, and reduce.

Example

"use strict";

var users = [
  { name: "Ada", age: 36 },
  { name: "Ben", age: 17 },
  { name: "Cleo", age: 29 }
];

var adults = users.filter(function(user) {
  return user.age >= 18;
}).map(function(user) {
  return user.name;
});

console.log(adults);

Part by part: "use strict"; enables strict mode. var users creates an array of objects. filter returns only users whose age is 18 or older. map transforms each remaining user into their name. The final output is ["Ada", "Cleo"].

Common mistakes

  • Using let, const, or arrow functions in ES5 code. Fix: replace them with var and function expressions.
  • Assuming an if block creates a new scope. Fix: remember that var is function-scoped, not block-scoped.
  • Losing this inside callbacks. Fix: store it in a variable such as var self = this; or use bind.
  • Calling ES6 methods like Object.assign without support. Fix: use ES5-compatible code or add a polyfill.

When to use it

ES5 is best when compatibility matters more than modern syntax. ES6 or ES2015 is better when you can use a build step or target modern browsers.

Use ES5 when Use ES6 or ES2015 when
You must support older browsers or engines. You can transpile or target modern environments.
You are reading legacy code or generated output. You want cleaner syntax like classes and arrow functions.
You need a stable baseline without build tools. You want modules, destructuring, and block scope.

Practice

Guided exercise: write an ES5 function that filters even numbers from an array.

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

var evens = numbers.filter(function(n) {
  return n % 2 === 0;
});

console.log(evens);

Expected output: [2, 4].

Challenge: write an ES5 function expression that returns the sum of squares of an array. Hint: use map to square each number, then reduce to add them together.

Quick check

Question: Why does var inside an if block not create a new scope?

Answer: Because var is function-scoped or global-scoped in ES5. Blocks such as if, for, and while do not create new variable scopes.

Summary

ES5 is a compatibility-focused JavaScript baseline built around var, function expressions, prototypes, and core array methods. Understanding it helps you read older code, avoid modern syntax mistakes, and reason clearly about scope and callbacks.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ES5 – FAQs

Quick answers about learning ES5 in JavaScript.

This free note from Coding Now Tech Institute explains ES5 in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including ES5, is 100% free with no signup required.
With focused practice, most students grasp ES5 in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now