Skip to content

Commit e33e192

Browse files
committed
Edited ch07.asciidoc with Atlas code editor
1 parent 5b951b9 commit e33e192

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ch07.asciidoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ Let's switch protocols and learn ((("String#padStart", startref="sps7")))((("Str
10821082

10831083
JavaScript strings ((("Unicode", id="u7")))((("strings", "and Unicode", id="s7au")))are represented using UTF-16 code units.pass:[<span data-type="footnote" id="unicode-encodings">Learn more about <a href="https://mjavascript.com/out/unicode-encodings">UCS-2, UCS-4, UTF-16, and UTF-32</a>.</span>] Each code unit can be used to represent a code point in the `[U+0000, U+FFFF]` range--also known as the ((("BMP (basic multilinual plane)")))BMP, short for Basic Multilingual Plane. You can represent individual code points in the BMP plane using the `'\u3456'` syntax. You could also represent code units in the `[U+0000, U+0255]` range using the `\x00..\xff` notation. For instance, `'\xbb'` represents `'»'`, the `U+00BB` code point, as you can also verify by doing `String.fromCharCode(0xbb)`.
10841084

1085-
For code points beyond `U+FFFF`, you'd represent them as a surrogate pair. That is to say, two contiguous code units. For instance, the horse emoji (pass:[<code><img src="images/1f40e.png" style="width: 12px" alt="horse emoji" data-emoji-embed="running horse" /></code>]) code point is represented with the `'\ud83d\udc0e'` contiguous code units. In ES6 notation you can also represent code points using the `'\u{1f40e}'` notation (that example is also the horse emoji).
1085+
For code points beyond `U+FFFF`, you'd represent them as a surrogate pair. That is to say, two contiguous code units. For instance, the horse emoji (pass:[<code><img src="images/1f40e.png" class="emoji" alt="horse emoji" data-emoji-embed="running horse" /></code>]) code point is represented with the `'\ud83d\udc0e'` contiguous code units. In ES6 notation you can also represent code points using the `'\u{1f40e}'` notation (that example is also the horse emoji).
10861086

10871087
Note that the internal representation hasn't changed, so there are still two code units behind that single code point. In fact, `'\u{1f40e}'.length` evaluates to `2`, one for each code unit.
10881088

@@ -1211,7 +1211,7 @@ Let's look at more Unicode-related methods introduced in ES6.
12111211

12121212
==== String#codePointAt
12131213

1214-
We can use `String#codePointAt` to ((("String#codePointAt", id="scpa7")))get the numeric representation of a code point at a given position in a string. Note that the expected start position is indexed by code unit, not by code point. In the following example we print the code points for each of the three emoji in our demo 'pass:[<code><img src="images/1f40e.png" style="width: 12px" alt="horse" data-emoji-embed="running horse" /><img src="images/1f471.png" style="width: 12px" alt="man" data-emoji-embed="smiling idiot" /><img src="images/2764.png" style="width: 12px" alt="heart" data-emoji-embed="heart" /></code>]' string.
1214+
We can use `String#codePointAt` to ((("String#codePointAt", id="scpa7")))get the numeric representation of a code point at a given position in a string. Note that the expected start position is indexed by code unit, not by code point. In the following example we print the code points for each of the three emoji in our demo 'pass:[<code><img src="images/1f40e.png" class="emoji" alt="horse" data-emoji-embed="running horse" /><img src="images/1f471.png" class="emoji" alt="man" data-emoji-embed="smiling idiot" /><img src="images/2764.png" class="emoji" alt="heart" data-emoji-embed="heart" /></code>]' string.
12151215

12161216
[source,javascript]
12171217
----

0 commit comments

Comments
 (0)