File size: 1,249 Bytes
780c9fe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
---
title: Number.prototype.valueOf()
short-title: valueOf()
slug: Web/JavaScript/Reference/Global_Objects/Number/valueOf
page-type: javascript-instance-method
browser-compat: javascript.builtins.Number.valueOf
sidebar: jsref
---
The **`valueOf()`** method of {{jsxref("Number")}} values returns the value of this number.
{{InteractiveExample("JavaScript Demo: Number.prototype.valueOf()")}}
```js interactive-example
const numObj = new Number(42);
console.log(typeof numObj);
// Expected output: "object"
const num = numObj.valueOf();
console.log(num);
// Expected output: 42
console.log(typeof num);
// Expected output: "number"
```
## Syntax
```js-nolint
valueOf()
```
### Parameters
None.
### Return value
A number representing the primitive value of the specified {{jsxref("Number")}} object.
## Description
This method is usually called internally by JavaScript and not explicitly in web code.
## Examples
### Using valueOf
```js
const numObj = new Number(10);
console.log(typeof numObj); // object
const num = numObj.valueOf();
console.log(num); // 10
console.log(typeof num); // number
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("Object.prototype.valueOf()")}}
|