InterviewHubPRO
Section Overview
Q3

Question 3 of 521

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

1%
JavaScript Internals (521 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What is the difference between JavaScript and ECMAScript?

In Simple Words:

  • ECMAScript (ECMA-262) is the official specification and standardized language definition created and maintained by the Ecma International technical committee TC39 (Technical Committee 39). It defines the syntax, grammar, types, execution semantics, and built-in standard objects (like Array, Promise, Proxy, Reflect).
  • JavaScript is a concrete programming language and implementation of the ECMAScript standard, enhanced with host environment APIs:
    • In Web Browsers: JavaScript = ECMAScript Core + Web APIs (DOM, Window, Fetch, WebSockets, Canvas, WebGL, LocalStorage).
    • In Node.js: JavaScript = ECMAScript Core + Server APIs (File System fs, http, process, Buffer, Streams, Worker Threads).

TC39 Release Stages:

  1. Stage 0 (Strawman): Idea submission.
  2. Stage 1 (Proposal): Formal problem statement and initial syntax sketch.
  3. Stage 2 (Draft): Precise formal specification with spec language.
  4. Stage 3 (Candidate): Feature complete, signed off for engine implementations.
  5. Stage 4 (Finished): Ships in test262 test suite and merged into annual standard (e.g. ES2024).

Practical Code Example

javascript
// 1. ECMAScript Core feature vs Host Environment API

// ECMAScript Core: Pure algorithmic logic, defined in ECMA-262
const calculateSum = (numbers) => {
  return numbers
    .filter((n) => typeof n === "number" && !Number.isNaN(n))
    .reduce((acc, curr) => acc + curr, 0);
};

// 2. Browser Host Environment API (DOM & Web API) - NOT part of ECMAScript spec:
if (typeof window !== "undefined" && typeof document !== "undefined") {
  const heading = document.createElement("h1");
  heading.textContent = `Result: ${calculateSum([10, 20, 30])}`;
  // document.body.appendChild(heading);
}

// 3. Node.js Host Environment API (process & buffers) - NOT part of ECMAScript spec:
if (typeof process !== "undefined" && process.versions && process.versions.node) {
  console.log("Running in Node.js runtime version:", process.version);
}

// 4. Modern ECMAScript feature check (Object.groupBy - ES2024):
const inventory = [
  { name: "Asparagus", type: "vegetables" },
  { name: "Banana", type: "fruit" },
  { name: "Carrot", type: "vegetables" },
];

if (typeof Object.groupBy === "function") {
  const grouped = Object.groupBy(inventory, ({ type }) => type);
  console.log("Grouped inventory:", Object.keys(grouped)); // ["vegetables", "fruit"]
}