Movatterモバイル変換


[0]ホーム

URL:


26. Unicode in ES6
Table of contents
Please support this book:buy it (PDF, EPUB, MOBI) ordonate
(Ad, please don’t block.)

26.Unicode in ES6

This chapter explains the improved support for Unicode that ECMAScript 6 brings. For a general introduction to Unicode, read Chap. “Unicode and JavaScript” in “Speaking JavaScript”.



26.1Unicode is better supported in ES6

There are three areas in which ECMAScript 6 has improved support for Unicode:

Additionally, ES6 is based on Unicode version 5.1.0, whereas ES5 is based on Unicode version 3.0.

26.2Escape sequences in ES6

There are three parameterized escape sequences for representing characters in #"#_where-can-escape-sequences-be-used" aria-hidden="true">#

The escape sequences can be used in the following locations:

 \uHHHH\u{···}\xHH
Identifiers 
String literals
Template literals
Regular expression literalsOnly with flag/u

Identifiers:

> const hello = 123;> hell\u{6F}123

String literals:

Template literals:

> `hell\u{6F}` // cooked'hello'> String.raw`hell\u{6F}` // raw'hell\\u{6F}'

Regular expressions:

26.2.2Escape sequences in the ES6 spec

Various information:

26.2.2.1Regular expressions

The spec distinguishes between BMP patterns (flag/u not set) and Unicode patterns (flag/u set). Sect. “Pattern Semantics” explains that they are handled differently and how.

As a reminder, here is how grammar rules are be parameterized in the spec:

You can see this parameterization in action in Sect. “Patterns”, where the subscript[U] creates separate grammars for BMP patterns and Unicode patterns:

Sect. “CharacterEscape” explains how various escape sequences are translated tocharacters (roughly: either code units or code points).

Further reading

JavaScript has a Unicode problem” (by Mathias Bynens) explains new Unicode features in ES6.

Next:27. Tail call optimization

[8]ページ先頭

©2009-2025 Movatter.jp