ValueOf() method
The valueOf() method in TypeScript is used to return the primitive value of the specified number object.
Syntax:
number.valueOf();
Example 1: In this example, we have used the ValueOf() method.
Javascript
// valueOf() let num = new Number(30); console.log(num.valueOf()); |
Output:
30
Example 2: In this example, we have used the valueOf() method.
Javascript
// valueOf() method let num4 = new Number(563); console.log( "Number Method: tovalueOf()" ); console.log( typeof num4 ) console.log(num4 ) console.log(num4 .valueOf()) |
Output:
Number Method: tovalueOf()
number
[Number: 563]
563
Difference Between valueof and keyof in TypeScript
In this article, we are going to learn the difference between valueOf() and keyof in TypeScript.
Contact Us