Course: JavaScript

Progress (0%)

  1. Foundation

  2. Numbers

  3. Strings

  4. Conditions

  5. Loops

  6. Arrays

  7. Functions

  8. Objects

  9. Exceptions

  10. HTML DOM

  11. CSSOM

  12. Events

  13. Drag and Drop

  14. opt Touch Events

  15. Misc

  16. Project: Analog Clock

JavaScript Strings - Unicode Quiz

Quiz 6 12 questions

Prerequisites for the quiz

  1. JavaScript Strings — Unicode

Are you ready?

12 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Which of the following character encoding schemes does JavaScript use to represent strings?
JavaScript uses the UTF-16 character encoding scheme. Thus, the correct choice is (B). For more info, refer to JavaScript Strings — Unicode.

Consider this definition:

"A table of characters along with their corresponding codes."

Which of the following terms best aligns with this definition?
A character set, for e.g. ASCII, Windows-1252, Unicode, can be thought of as a table of characters along with their corresponding codes. Hence, the correct choice is (A). For more info, refer to JavaScript Strings — Unicode.
Unicode is a universal character set, supporting characters from a ton of different languages, unlike ASCII. True or false?
That's true. Unicode indeed is a universal set. It was developed to address this issue with other character sets that they couldn't be used for one language or the other. For more info, refer to JavaScript Strings — Unicode.
A JavaScript string is a sequence of signed 16-bit integers. True or false?
False. A JavaScript string is a sequence of unsigned 16-bit integers. For more info, refer to JavaScript Strings — Unicode.
A JavaScript string is a sequence of unsigned 32-bit integers. True or false?
False. A JavaScript string is a sequence of unsigned 16-bit integers. For more info, refer to JavaScript Strings — Unicode.

The character 'a' has the character code 97 (in decimal) and 'b' has the character code 98 (in decimal).

What does the following code log?
var str = 'a';
console.log(str.charCodeAt())
When charCodeAt() is called without an argument, it defaults to 0. Thus str.charCodeAt() is equivalent to str.charCodeAt(0), returning the code of the first character, 'a', which is 97. Hence, the correct choice is (B). For more info, refer to JavaScript Strings — Unicode: charCodeAt().
What does the following code log?
var str = 'a';
console.log(str.charCodeAt(0) === str.codePointAt(0));
Since 'a' is comprised of just one code unit in UTF-16, both str.charCodeAt(0) and str.codePointAt(0) return back the same number (which is the value of the character's code unit). Hence, the correct choice is (A). For more info, refer to JavaScript Strings — Unicode: charCodeAt() and JavaScript Strings — Unicode: codePointAt().

Given that 'a' has the character code 97 (in decimal), which is 61 (in hex), what does str hold in the code below?
var str = '\u62';
The code throws an error because the Unicode escape sequence \u62 is invalid — we can't have less than 4 digits following the u character and they all must be hexadecimal digits (0 - 9, a - f). Hence, the correct choice is (D). For more info, refer to JavaScript Strings — Unicode: Unicode escape sequences.

Given that 'a' has the character code 97 (in decimal), which is 61 (in hex), what does str hold in the code below?
var str = '\u{62}';
The Unicode escape sequence \u{62} resolves to a character in Unicode with the code point 62 (in hex). Since this corresponds with the character 'b', str simply becomes 'b'. This goes with choice (C). For more info, refer to JavaScript Strings — Unicode: Unicode escape sequences.
What does the following code log?
var str = '🙂';
console.log(str.charCodeAt(0) === str.codePointAt(0));
Since the '🙂' character is comprised to two code units (the first one being a high surrogate), str.charCodeAt(0) won't return the same thing as str.codePointAt(0). So the code above logs false and this goes with choice (B). For more info, refer to JavaScript Strings — Unicode: charCodeAt() and JavaScript Strings — Unicode: codePointAt()..
What does '🙂😃'.length return?
It returns 4 since each of the given emoticon characters is comprised of two code units. For more info, refer to JavaScript Strings — Unicode: The length property.
What does the following code log?
var str = 'Hello 🙂';
console.log(str.length);
console.log([...str].length);
str.length returns 8 since 'Hello ' consists of 6 code units and '🙂' consists of two. [...str].length returns 7 because it distinguishes between individual characters, not code units. Together, we get the logs 8 followed by 7. This goes with choice (C). For more info, refer to JavaScript Strings — Unicode: The string iterator.