QuestenaPractice that shows what to review next
Question 101

When for...of iterates a string containing a character represented by one UTF-16 surrogate pair, how is that pair handled?

  1. The pair is consumed together as one code pointCorrect answer
  2. Each code unit always becomes a separate iteration
  3. The loop throws because the string contains two code units
  4. The pair is skipped because only ASCII characters are iterable

Explanation

String iteration advances by Unicode code point, so the two code units of a valid surrogate pair are delivered together for that code point. Treating every code unit as a separate iteration confuses for...of with direct UTF-16 indexing; a code point still need not equal a full grapheme.

Continue with this test

Start practice
Question 101: When for...of iterates a string containing a character… · JavaScript Fundamentals · Questena