Q: Which of the below number object functions gives the number's value back?
-
A
toString()
-
B
valueOf()
-
C
toLocaleString()
-
D
toPrecision()
B
Answer:
B
Explanation:
valueOf() is a method that is available on many JavaScript objects, and it returns the primitive value of the object.
For example, if you have a number object x that was created using the Number constructor,
you can use the valueOf() method to get the primitive value of x.
Here's an example:
let x = new Number(5);
console.log(x.valueOf()); // Output: 5
Related Topic:
Share Above MCQ