JS: ECMAScript 2015 (ES6)
Over 30 major features are added to the language, effectively making JavaScript a new language.
Here is a quick overview of new features.
Let
let is like var , but with a clean block-level scope.
Const
const is similar to let, except you can't change its value once set.
Arrow function
you can write function like this
((x, y) => { return x + y; });
arrow function doesn't have this-binding , and no arguments Object, no Function Name Hoisting .
Function argument default values
function parameter can specify a default value.
// function with default parameter values function f(x = 4, y = 2) { return [x, y]; } console.log(f()); // [ 4, 2 ]
Rest parameters
function can now specify to take any number of parameters, by syntax ...args
// 2 parameters plus a rest param function ff(a, b, ...c) { return c; } console.log(ff(1, 2, 3, 4)); // [ 3, 4 ]
Assignment pattern
pattern matching for assignment
// assignment pattern let [x, y, z] = [3, 4, 6];
Object literal expression, extensions
Computed property keys
new syntax for object literal to have computed property key by an expression.
{ [expr]: value }
// Object Literal Expression, Computed Property Keys const expr = "cat"; const xobj = { [expr]: 4 }; console.log(xobj); // { cat: 4 }
Method definition shorthand
new syntax shorthand for defining methods in object literal expression.
{
…,
method_name (param) {function_body},
…
}
// object literal expression method definition shorthand const jj = { xmethod(x) { console.log("xmethod called with arg:", x); }, gg: 4, }; console.log(jj.xmethod(2)); // xmethod called with arg: 2
Key without value shorthand
{ var_name }
means
{ var_name: var_name }
if var_name is not defined, it's an error.
// key without value shorthand for object literal expression const dog = 3; const cat = 4; const jj = { dog, cat }; console.log(jj); // { dog: 3, cat: 4 }
Template string
allows you to embed variable or expression in a string, or have literal newline char.
console.log(`2 + 3 is: ${2 + 3}`); // 2 + 3 is: // 5 // before, you have to use + to eval expression, and \n for newline. console.log( "2 + 3 is:\n" + (2 + 3) ); // 2 + 3 is: // 5
Interface, iterable, iterator, generator
Iterable is new. It is a like a delayed array, items are generated at time it is used.
array is now an iterable.
for-of loop and spread operator works with iterables.
iterator is created to support iterable.
interface and generators are created to support iterable.
- JS: Interface
- Iterator prototype
- JS: Generator
Generator Function is created to support creating iterable.
Spread operator
The spread operator is 3 dots:
...xArray
What it does is insert the array items (into a array, or as function args). The operand can be any iterable.
For-of loop
loop thru an iterable.
Set object
Set object is data structure of set. That is, a collection of unique values.
Map object
Map object is a data structure of dictionary. Similar to Data Object, but now designed to be used as a data structure, have length, keys can be any type (not just string), etc.
const xx = new Map(); // add new item xx.set(1, "n1"); xx.set(2, "n2"); console.log(xx); // Map { 1 => "n1", 2 => "n2" }
Reflect
The Reflect object is used as namespace to host a group of static functions.
Reflect methods typically duplicate operator behavior in function form, or provides a more strict or better version of existing methods.
Class
class is a new keyword that lets you conveniently define object and its prototype.
New keywords are:
class,
constructor,
static,
extends,
super.
- JS: Define Class
- JS: Class static fields and methods
- JS: Class extends (subclassing)
- JS: “super” keyword
Subclassing
- Array is subclassable
- RegExp is subclassable
- Function is subclassable
- Promise is subclassable
Regex
Regex flag u (unicode)
New regex flag u. For unicode. Treat string as sequence of unicode characters, and more.
new property RegExp.prototype.unicode.
Value is true if flag u is on.
Regex flag y (sticky)
New regex flag y. For “sticky”.
when on:
- The beginning position of the matched substring must be the same as
regexObj.lastIndex. - If a match is found,
regexObj.lastIndexis set to the end position of the matched substring. If no match is found,regexObj.lastIndexis set to 0.
new property RegExp.prototype.sticky.
Value is true if flag y is on.
New properties for RegExp.prototype
RegExp.prototype.flags.
Value is a string of all the flags that is on.
methods:
RegExp.prototype [ Symbol.match ]RegExp.prototype [ Symbol.replace ]RegExp.prototype [ Symbol.search ]RegExp.prototype [ Symbol.split ]
These are the hidden methods that many of the regex methods actually call. These are created so that it can be customized by overriding their values.
New array properties
new array constructor properties
- convert array-like and iterable to array.
- JS: Array.from
- function form of array literal expression
- JS: Array.of ♠
new array prototype properties
- JS: Array.prototype.copyWithin
- JS: Array.prototype.fill
- JS: Array.prototype.find
- JS: Array.prototype.findIndex
- JS: Array.prototype.entries
- JS: Array.prototype.keys
- JS: Array.prototype.values
Array.prototype[Symbol.iterator](same as Array.prototype.values)Array.prototype[Symbol.unscopables]
New string properties
static methods
String.fromCodePoint(...codePoints)— builds a string from Unicode code points (including those above U+FFFF)String.raw(template, ...substitutions)— tag function that returns the raw template string (no escape processing)
string methods
String.prototype.localeCompareString.prototype.normalizeString.prototype[Symbol.iterator]
New object methods
New function properties
- function property
"name". JS: Function Name Property
New number properties
Number.isFiniteNumber.isIntegerNumber.isNaNNumber.isSafeIntegerNumber.parseFloatNumber.parseInt
Number.EPSILONNumber.MIN_SAFE_INTEGERNumber.MAX_SAFE_INTEGER
New math methods
Math[Symbol.toStringTag]
Math.signMath.truncMath.cbrt
Math.expm1Math.log1pMath.log10Math.log2
Math.hypot
Math.sinhMath.coshMath.tanhMath.asinhMath.acoshMath.atanh
Math.froundMath.clz32Math.imul
Html-like comments
formally recognize html comment.
Block-level function declaration
now allow function declaration inside a block.
// es2015 block-level function declaration function f() { function g(x) { return x + 1; } return g(1); } console.log(f()); // 2
Module, keyword “import”, “export”
Unicode escape syntax
Now you can escape unicode by
\u{4_to_6_hex_digits}
Octal and binary literals
// octal notation console.assert(0o10 === 8); // binary console.assert(0b10 === 2);
New.target
new.target is a special meta-property in JavaScript that tells you whether a function (or class constructor) was invoked using the new keyword.
function ff() { if (new.target) console.log("called with new.\n", "new.target value is: ", new.target); else console.log("called as function.\n", "new.target value is:", new.target); } new ff(); // called with new. // new.target value is: [Function: ff] ff(); // called as function. // new.target value is: undefined
Promise
PromisePromise.prototypePromise.allPromise.racePromise.rejectPromise.resolve
Promise.prototype.catch ( onRejected )Promise.prototype.constructorPromise.prototype.then ( onFulfilled , onRejected )Promise.prototype [ @@toStringTag ]
__proto__
document the property key __proto__ to get/set parent.
It was from Firefox.
Arraybuffer, dataview, typed array
ArrayBufferDataView
Int8ArrayInt16ArrayInt32ArrayUint8ArrayUint16ArrayUint32ArrayUint8ClampedArrayFloat32ArrayFloat64Array
Weakmap, weakset
Proxy
it allows you to create a new object, such that you can intercept any operation with the object.
order of own property keys
now Object.getOwnPropertyNames return properties in a specific order.
- Integer indices in ascending numeric order (for array keys).
- Other string keys in creation order.
- Symbol keys in creation order
reference:
- 19.1.2.7 Object.getOwnPropertyNames ( O ) ECMAScript 2015 §Fundamental Objects#sec-object.getownpropertynames
- 19.1.2.8.1 Runtime Semantics: GetOwnPropertyKeys ( O, Type ) ECMAScript 2015 §Fundamental Objects#sec-getownpropertykeys
- ECMAScript 2015, 9.1.12 [[OwnPropertyKeys]] ECMAScript 2015 §Ordinary and Exotic Objects Behaviours#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
before, it does not specify order
- getOwnPropertyNames
- ECMAScript Language Specification - ECMA-262 Edition 5.1#sec-15.2.3.4
Tail call optimisation (recursion)
Function.prototype.bind (prototype of bound functions)
In ES5, a function created with Function.prototype.bind() always had Function.prototype as its parent object.
In ES6, the parent is the same as target function's parent.
function f() {} Object.setPrototypeOf(f, Array.prototype); const bound = Function.prototype.bind.call(f, null); console.log(Object.getPrototypeOf(bound) === Array.prototype); // true in ES2016
19.2.3.2: In ECMAScript 2015, the [[Prototype]] internal slot of a bound function is set to the [[GetPrototypeOf]] value of its target function. In the previous edition, [[Prototype]] was always set to %FunctionPrototype%.
- from
- ECMAScript 2015 §Annex E ECMAScript 2015 §Annex E#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions
- 19.2.3.2 Function.prototype.bind ( thisArg , ...args) ECMAScript 2015 §Fundamental Objects#sec-function.prototype.bind
Misc
Annex b
- hoisted block-level function declaration
- String.prototype HTML methods
- RegExp.prototype.compile
in js ES 2015, what does these mean Annex b hoisted block-level function declaration String.prototype HTML methods RegExp.prototype.compile
(ai answer)
Annex B in the ES2015 (ECMAScript 2015) spec is titled “Additional ECMAScript Features for Web Browsers.” These features are normative for web browsers (required for compatibility with existing web pages) but optional for other hosts. They are legacy behaviors with undesirable characteristics; the spec advises against using them in new code.
1. Hoisted block-level function declaration
In pure ES2015, a function declaration inside a block is block-scoped (hoisted only within the block).
Annex B adds web-compatibility semantics (mainly for non-strict/sloppy mode):
- A
var-like binding is also created and hoisted to the enclosing function scope (initiallyundefined). - When the block executes and the function declaration is evaluated, the function object is assigned to that outer binding.
- A block-scoped binding still exists as well.
Result: the function can sometimes be visible outside its block (like old pre-ES6 browser behavior), but only under specific conditions defined in the annex. Strict mode generally sticks to pure block-scoping.
2. String.prototype HTML methods
Legacy methods that wrap a string in HTML tags, e.g.:
"text".bold()→"<b>text</b>""text".italics()→"<i>text</i>""text".link("url")→"<a href=\"url\">text</a>""text".anchor("name")→"<a name=\"name\">text</a>"- Also:
big,blink,fixed,fontcolor,fontsize,small,strike,sub,sup
They exist only for old web compatibility and are deprecated. Prefer modern alternatives (template literals, DOM APIs, etc.).
3. RegExp.prototype.compile
Deprecated method that recompiles an existing RegExp object with a new pattern and flags:
const re = new RegExp("foo", "gi"); re.compile("newfoo", "g"); // mutates re in place
It duplicates the RegExp constructor but mutates the existing object (making source/flags mutable after creation). Exists solely for backwards compatibility; create a new RegExp instead.
Summary: All three are legacy web-browser compatibility features in Annex B. Avoid them in new code.
in JavaScript ECMAScript 2015, there are these. what does it mean. * Object static methods accept primitives * miscellaneous
(ai answer) 2026-11-03
Object static methods accept primitives
Several Object.* methods used to throw a TypeError if you passed a primitive (null, undefined, number, string, boolean, etc.).
In ES6 they coerce the argument with ToObject (or treat it specially):
console.log(Object.keys("abc")); // ["0", "1", "2"] console.log(Object.getOwnPropertyNames(42)); // [] console.assert((Object.freeze(true)) === true); // no longer throws console.assert(Object.getPrototypeOf("hi") === String.prototype);
Affected methods include Object.keys, getOwnPropertyNames, getOwnPropertyDescriptor, getPrototypeOf, isExtensible, isFrozen, isSealed, preventExtensions, seal, and freeze.
Miscellaneous
This is usually a catch-all category in compat tables covering the smaller spec changes above, plus things like:
- Accessor methods (
get/set) created in object literals are no longer constructors (they lack a.prototypeand can’t be called withnew) - Other minor internal-slot / prototype adjustments (e.g. NativeError constructors)
Reference
- one single file, 3.7 megabytes.
- https://262.ecma-international.org/6.0/
- one single file, local copy.
- ECMAScript 2015 Language Specification – ECMA-262 6th Edition
- multiple files. one page per chapter.
- ECMAScript 2015 Language Specification – ECMA-262 6th Edition