File size: 1,271 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 |
---
title: Boolean.prototype.valueOf()
short-title: valueOf()
slug: Web/JavaScript/Reference/Global_Objects/Boolean/valueOf
page-type: javascript-instance-method
browser-compat: javascript.builtins.Boolean.valueOf
sidebar: jsref
---
The **`valueOf()`** method of {{jsxref("Boolean")}} values returns the primitive value of a
{{jsxref("Boolean")}} object.
{{InteractiveExample("JavaScript Demo: Boolean.prototype.valueOf()")}}
```js interactive-example
const x = new Boolean();
console.log(x.valueOf());
// Expected output: false
const y = new Boolean("Mozilla");
console.log(y.valueOf());
// Expected output: true
```
## Syntax
```js-nolint
valueOf()
```
### Parameters
None.
### Return value
The primitive value of the given {{jsxref("Boolean")}} object.
## Description
The `valueOf()` method of {{jsxref("Boolean")}} returns the primitive value
of a `Boolean` object or literal `Boolean` as a Boolean data type.
This method is usually called internally by JavaScript and not explicitly in code.
## Examples
### Using `valueOf()`
```js
const x = new Boolean();
const myVar = x.valueOf(); // assigns false to myVar
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{jsxref("Object.prototype.valueOf()")}}
|