A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-number-valueof-method/ below:

JavaScript Number valueOf( ) Method

JavaScript Number valueOf( ) Method

Last Updated : 22 May, 2023

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
let num=NaN;
console.log(num.valueOf());            

Output:

NaN

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

JavaScript
let num=213;
console.log(num.valueOf());            

Output:

 213

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

JavaScript
let num=-213;
console.log(num.valueOf());            

Output:

-213

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

JavaScript
let 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
let num=0/0;
console.log(num.valueOf());            

Output:

Nan

Supported Browsers:

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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4