The valueOf() is a number method we can use to return the primitive value of a number. The primitive value is the value of type undefined, null, boolean, number, string, or symbol.
Note: The
valueOf()method is used internally by Javascript. It is not used explicitly in web code.
The valueOf() method is declared as follows:
num.valueOf()
num: The number whose primitive value is returned.Note: This method does not accept any parameters.
The valueOf() method returns a number which is the primitive value of num.
The valueOf() method is supported by the following browsers:
Consider the code snippet below, which demonstrates the use of the valueOf() method:
var num = 15.99console.log("Value of 15.99:",num.valueOf());num = 1/0console.log("Value of 1/0:",num.valueOf());num = 0/0console.log("Value of 0/0:",num.valueOf());num = 0console.log("Value of 0:",num.valueOf());num = -15.99console.log("Value of -15.99:",num.valueOf());
Free Resources