CRT-600 practice question 14 of 30
Given the code below: Which three code segments result in a correct conversion from number to string? Choose 3 answers
Full set: 223 questionsIn JavaScript a numeric value can be converted to its string representation by (1) invoking its own Number.prototype.toString() method, (2) calling the built-in String constructor as a function, or (3) forcing implicit coercion through concatenation with an empty string or a template literal.
Option A invokes toString(); option D calls String(numValue); option B uses a template literal (back-ticked ${numValue} ) which interpolates numValue and always returns a string. All three therefore return a correctly-typed string.
C. Number objects have no toText() method; call throws TypeError.
E. (String)numValue is not valid ECMAScript casting syntax; results in SyntaxError at parse time.
1. ECMA-262
14ᵗʰ Ed. (2023)
§21.1.3.29 “Number.prototype.toString” – describes numeric toString conversion.
2. ECMA-262
§19.1.1.1 “The String Constructor Called as a Function” – String(value) returns ToString(value).
3. ECMA-262
§7.1.17 “ToString Abstract Operation” – implicit coercion via concatenation/template literals.
4. ECMA-262
§12.2.9 Template Literals – evaluation always produces a String value.
5. Salesforce Lightning Web Components Dev Guide
“JavaScript Basics → Type Coercion”
para 4 – shows ‘’ + numValue and ${numValue} patterns for number-to-string conversion.
Keep practicing
Take the free CRT-600 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-600 practice questions
- Question 2A developer has the function, shown below, that is called when a page loads. function onl…
- Question 3A developer needs to test this function: 01 const sum3 = (arr) => ( 02 if (!arr.length) r…
- Question 4Refer to the code below: Const resolveAfterMilliseconds = (ms) => Promise.resolve ( setTi…
- Question 10Refer to the following code block: class Animal{ constructor(name){ this.name = name; } m…
- Question 11A developer needs to debug a Node.js web server because a runtime error keeps occurring a…
- Question 12Refer to the string below: const str = 'Salesforce'; Which two statements result in the w…
