This JavaScript tutorial explains how to use the Number technique referred to as valueOf() with syntax and examples.
Description
In JavaScript, valueOf() is a Number approach that is used to return the primitive value of a Number object. Because valueOf() is a approach of the Number object, it need to be invoked via a unique instance of the Number class.
Syntax
In JavaScript, the syntax for the valueOf() technique is:
number.valueOf();
Parameters or Arguments
There are no parameters or arguments for the valueOf() method.
Returns
The valueOf() approach returns the primitive price of the calling Number object.
Note
The valueOf() method does not exchange the cost of the authentic number.
Example
Let’s take a seem to be at an instance of how to use the valueOf() approach in JavaScript.
For example:
var totn_number = new Number(123);
console.log(totn_number);
console.log(totn_number.valueOf());
In this example, we have declared a Number object referred to as totn_number that is assigned the fee of 123. We have then invoked the valueOf() method of the totn_number variable to return its primitive value.
We have written the output of the valueOf() technique to the net browser console log, for demonstration purposes, to show what the valueOf() method returns.
The following will be output to the net browser console log:
Number {123}
123
In this example, the first output to the console log suggests the Number object. Whereas, the second output to the console log suggests 123 which is the primitive price of the totn_number Number object.
Leave a Review