ES6 / 2015
ES20152015The largest single revision of the language. Block scoping, lexical `this`, class syntax, and a standardised Promise — the foundation of every later feature.
Class syntax is sugar over prototypes, but with real rules: methods are non-enumerable, constructors require `new`, and class bodies are always strict. `extends` wires up `super` and `instanceof` across the whole chain.
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return this.name + " makes a sound";
}
}
class Dog extends Animal {
constructor(name) {
super(name);
this.species = "dog";
}
speak() {
return this.name + " barks";
}
}
const rex = new Dog("Rex");
console.log(rex.speak());
console.log("instanceof Dog / Animal:", rex instanceof Dog, rex instanceof Animal);
console.log("static chain:", Object.getPrototypeOf(Dog) === Animal);
console.log("own enumerable keys:", Object.keys(rex)); // instance fields only| V8 | `#x` is enforced at parse time and invisible to `Object.keys` and `getOwnPropertyNames` — true privacy, not a naming convention. Shipped in V8 7.4 (2019). |
|---|---|
| Node.js | Private fields landed in Node 12 (V8 7.4); the ergonomic `#x in obj` membership check since Node 16. |
| Deno | Full `#` support, including `#x in obj`, from the very first 1.0 release — it launched after the feature was already standard. |
| Bun | JavaScriptCore implements private fields natively, with semantics that match V8 exactly. |