Q. Which of the following number object function returns the value of the number?

  • (A) toString()
  • (B) valueOf()
  • (C) toLocaleString()
  • (D) toPrecision()
πŸ’¬ Discuss
βœ… Correct Answer: (B) valueOf()
Explanation:

valueOf():
Returns the primitive value of a Number object.
βœ… Correct answer

toString():
Converts the number to a string.

toLocaleString():
Returns a string with a language-sensitive representation of the number.

toPrecision():
Formats the number to a specified precision and returns it as a string.

Example:

let num = new Number(42);

console.log(num.valueOf()); // 42
console.log(num.toString()); // "42"
console.log(num.toLocaleString()); // e.g., "42" (depends on locale)
console.log(num.toPrecision(2)); // "42"

? Only valueOf() returns the raw numeric value.

βœ… Answer: (B) valueOf()

Explanation by: Mr. Dubey

valueOf():
Returns the primitive value of a Number object.
βœ… Correct answer

toString():
Converts the number to a string.

toLocaleString():
Returns a string with a language-sensitive representation of the number.

toPrecision():
Formats the number to a specified precision and returns it as a string.

Example:

let num = new Number(42);

console.log(num.valueOf()); // 42
console.log(num.toString()); // "42"
console.log(num.toLocaleString()); // e.g., "42" (depends on locale)
console.log(num.toPrecision(2)); // "42"

? Only valueOf() returns the raw numeric value.

βœ… Answer: (B) valueOf()

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
343
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Durgesh
Publisher
πŸ“ˆ
91%
Success Rate