Javascript Developer JSE 40 01 · Free Practice Question Easy

Question 2

Q115 - Data Types


We want to convert the number 1024 to a String type

and store the result in a variable s


Point out the correct statement:


  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: C

Explanation

Topic: String()


Try it yourself:


Explanation:

The String() constructor converts a value to a string.

https://www.w3schools.com/jsref/jsref_string.asp


(There is a similar question Q515.)


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

A. There is no built-in function called NumberToString() in JavaScript. Using this function will result in an error, as it is not a valid method for converting a number to a string. The correct method is to use the String() function for this conversion.

B. Adding a number to a string in JavaScript will result in concatenation, not conversion. In this case, the number 1024 will be concatenated with the string "0", resulting in "10240", not a proper conversion to a string.

C. Using the String() function is the correct way to convert a number to a string in JavaScript. This function explicitly converts the number 1024 to a string and stores it in the variable s.

D. Using the Number() function will not convert the number 1024 to a string; instead, it will keep it as a number type. This is not the correct approach for converting a number to a string in JavaScript.

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