What does a tag function receive in tag`Hello ${name}!`?
The tag decides how parts and values are combined and may return any value. This powers String.raw, HTML escaping and libraries such as styled-components.
Strings · Exercise 1 of 4
Fifteen multiple-choice questions on JavaScript strings: immutability, quotes and template literals, escape sequences, indexing, Unicode length, slice vs substring, comparison, localeCompare, String() vs toString(), wrapper objects, tagged templates and String.raw. Pick an option to check your answer instantly.
What does a tag function receive in tag`Hello ${name}!`?
The tag decides how parts and values are combined and may return any value. This powers String.raw, HTML escaping and libraries such as styled-components.
What is the length of String.raw`a\nb`?
String.raw returns the raw source text, so \n is not converted to a line break. A normal template literal `a\nb` has length 3.
A loop produces 10,000 lines of CSV. Which approach is clear and predictable?
Strings cannot be modified in place. Collecting parts and joining once is idiomatic (engines also optimise +=, but join keeps intent clear).
What do "hello".includes("z") and "hello".indexOf("z") return?
includes answers yes/no; indexOf gives a position, or -1 when not found. Both are case-sensitive.
Which escape sequence puts a line break inside a double-quoted string?
\n is the line-feed character. "\n" would produce a literal backslash followed by n, and <br> is HTML, not JavaScript.
Timed online tests with instant scores and explanations.