O método valueOf()
retorna o valor primitivo contido no objeto Number
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Sintaxe
numObj.valueOf()
Valor retornado
Um número representando o valor primitivo do objeto Number
.
Descrição
Este método normalmente é invocado internamente pelo JavaScript e não explicitamente em um código web.
Exemplos
Utilizando valueOf
var numObj = new Number(10);
console.log(typeof numObj); // object
var num = numObj.valueOf();
console.log(num); // 10
console.log(typeof num); // number
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Padrão | Definição inicial. Implementada no JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Number.prototype.valueOf' in that specification. |
Padrão | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.prototype.valueOf' in that specification. |
Padrão | |
ECMAScript (ECMA-262) The definition of 'Number.prototype.valueOf' in that specification. |
Padrão em tempo real |
Browser compatibility
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.