| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
valueOf() .
function MyNumberType(n) {
this.number = n;
}
MyNumberType.prototype.valueOf = function () {
return this.number;
};
const object1 = new MyNumberType(4);
console.log(object1 + 3);
// Expected output: 7
object.valueOf();
.
:
() valueOf . , . +new Number(). . .
JavaScript valueOf . .
Object valueOf . valueOf . , valueOf .
valueOf . valueOf Object .
valueOf . .
MyNumberType , valueOf . valueOf .
MyNumberType.prototype.valueOf = function () {
return customPrimitiveValue;
};
MyNumberType JavaScript .
valueOf JavaScript .
myNumberType.valueOf();
:
- toString() , String valueOf . , "[object type]" . , , .
function MyNumberType(n) {
this.number = n;
}
MyNumberType.prototype.valueOf = function () {
return this.number;
};
var myObj = new MyNumberType(4);
myObj + 3; // 7
+"5"; // 5 (string to number)
+""; // 0 (string to number)
+"1 + 2"; // NaN (doesn't evaluate)
+new Date(); // same as (new Date()).getTime()
+"foo"; // NaN (string to number)
+{}; // NaN
+[]; // 0 (toString() returns an empty string list)
+[1]; // 1
+[1, 2]; // NaN
+new Set([1]); // NaN
+BigInt(1); // Uncaught TypeError: Cannot convert a BigInt value to a number
+undefined; // NaN
+null; // 0
+true; // 1
+false; // 0
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.prototype.valueof |
This page was last modified on 2026 7 15 by MDN contributors.
ObjectObject.assign()Object.create()Object.defineProperties()Object.defineProperty()Object.entries()Object.freeze()Object.fromEntries()Object.getOwnPropertyDescriptor()Object.getOwnPropertyDescriptors()Object.getOwnPropertyNames()Object.getOwnPropertySymbols()Object.getPrototypeOf()Object.groupBy()Object.hasOwn()Object.is()Object.isExtensible()Object.isFrozen()Object.isSealed()Object.keys()Object.preventExtensions()Object.seal()setPrototypeOf()Object.values()Object.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |