TypeScript Number valueOf() Method

The valueOf() method in TypeScript is used to return the primitive value of the specified number object.
Syntax:

number.valueOf()

Parameter values: This method does not accept any parameter.

Return Value: The valueOf() method in TypeScript returns the primitive value of the specified number object.

Below examples illustrates the working of valueOf() function in TypeScript:
Example 1:

javascript



filter_none

edit
close

play_arrow

link
brightness_4
code

//valueOf()
var num3 = new Number(30);
console.log(num3.valueOf());

chevron_right


Output: 

30

Example 2:

javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// valueOf() method
let num4 = new Number(563);
console.log("Number Method: tovalueOf()");
console.log(typeof num4 )
console.log(num4 )
console.log(num4 .valueOf())

chevron_right


Output: 

Number Method: tovalueOf()
number
[Number: 563]
563
My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.