Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Number valueOf( ) Method

Improve Article
Save Article
  • Last Updated : 16 Mar, 2023
Improve Article
Save Article

JavaScript Number valueOf( ) method in JavaScript is used to return the primitive value of a number. This method is usually called internally by JavaScript and not explicitly in web code

Syntax:

number.valueOf()

Parameters: This method does not accept any parameter.

Return Value: The valueof() method in JavaScript returns a number representing the primitive value of the specified Number object. 

Below are examples of the Number valueOf( ) Method:

Example 1: In this example, the output comes out to be NaN as the value stored in the variable is NaN.

Javascript




var num=NaN;
console.log(num.valueOf());


Output:

NaN

Example 2: Passing a positive number as an argument in the valueOf() method. 

Javascript




var num=213;
console.log(num.valueOf());


Output:

 213

Example 3: Passing a negative number as an argument in the valueOf() method. 

Javascript




var num=-213;
console.log(num.valueOf());


Output:

-213

Example 4: Passing zero as an argument in the valueOf() method. 

Javascript




var num=0;
console.log(num.valueOf());


Output:

0

Example 5: Passing an equation(equating to infinite value) as an argument in the valueOf() method. 

Javascript




var num=0/0;
console.log(num.valueOf());


Output:

Nan

Supported Browsers:

  • Google Chrome 1 and above
  • Internet Explorer 4 and above
  • Firefox 1 and above
  • Apple Safari 1 and above
  • Opera 3 and above

We have a complete list of Javascript Number Objects methods, to check those please go through this Javascript Number Complete reference article.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!