Javascript Developer JSE 40 01 · Free Practice Question Easy

Question 11

Q414 - Data Types


Using the string interpolation technique, we can create the string

"I do not like travelling by plane"

and store it in the msg variable using the command:


  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

Explanation

Topic: template literals


Try it yourself:


Explanation:

Template literals use back-ticks (``) to define a string.

Template literals provide an easy way

to interpolate variables and expressions into strings.

https://www.w3schools.com/js/js_string_templates.asp


(There is a similar question Q314.)


Q414 (Please refer to this number, if you want to write me about this question.)

A. This choice correctly uses the string interpolation syntax ${} to insert the value of the variable means into the string. This results in the desired string "I do not like travelling by plane" being stored in the msg variable.

B. This choice uses double quotes for the string but does not use backticks for string interpolation. The variable means is not correctly inserted into the string, resulting in the literal string "I do not like travelling by ${ means }" being stored in the msg variable.

C. This choice uses single quotes instead of backticks for the string, which does not allow for string interpolation. The variable means is not correctly inserted into the string, resulting in the literal string "I do not like travelling by {means}" being stored in the msg variable.

D. This choice uses double quotes for the string but attempts to escape the curly braces around the variable means, which is unnecessary and incorrect. The backslash before the curly braces and the extra double quote at the end make the syntax invalid, resulting in an incorrect string being stored in the msg variable.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need