Annex B, "Additional ECMAScript Features for Web Browsers", is a normative annex of ECMA-262. It's required when the host is a web browser and optional for other hosts. Its own note is blunt: every feature in it has undesirable characteristics and would be removed if existing web pages didn't depend on it, so programmers shouldn't use or assume it in new code. It exists to make those legacy behaviours interoperable rather than leaving each browser to guess.
It has three parts:
- B.1 Additional syntax. HTML-like comments (
<!--starts a line comment, and-->does at the start of a line), allowed in scripts but not modules. Lenient regex patterns without theuorvflag: a lone]or{is a literal character, plus legacy escapes. - B.2 Additional built-ins.
escapeandunescape;String.prototype.substr; the HTML methods (anchor,bold,link, …) that wrap a string in a tag;trimLeft/trimRightas aliases oftrimStart/trimEnd;Date.prototype.getYear,setYear,toGMTString;RegExp.prototype.compile. - B.3 Other semantics. Sloppy-mode rules for function declarations in blocks and
ifclauses, labelled functions,varredeclaring a catch parameter,for (var x = init in obj), the[[IsHTMLDDA]]slot that makesdocument.allact likeundefined, and a few browser-specific host hooks.
Not every legacy feature lives there. with and legacy octal literals (010) are in the main body, required everywhere but only in sloppy mode. In ES2019, __proto__ and __defineGetter__ were in Annex B; the current spec has them in the main body, marked Normative Optional, Legacy.
Optional doesn't mean absent: Node.js 24 isn't a browser, but its engine (V8) implements these features, so every example below runs there.