A
Q. Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator)
- Correct Answer - Option(B)
- Views: 17
- Filed under category JavaScript
- Hashtags:
A
In JavaScript, we can convert a boolean (false) to a string in two ways:
Using .toString() method
Using String() function
Why Not Other Options?
Since both methods work, the best answer is (B) Both false.toString() and String(false).
var str2 = String(false);
console.log(str2); // Output: "false"
var str1 = false.toString();
console.log(str1); // Output: "false"
You must be Logged in to update hint/solution
Be the first to start discuss.
Discusssion
Login to discuss.