The valueOf function method in JavaScript returns the original value of the specified object. Usage:
object.valueOf()object is required and the parameter is any inherent JScript object.
The valueOf method definition of each JavaScript intrinsic object is different.
对象 | 返回值 |
Array | 数组的元素被转换为字符串,这些字符串由逗号分隔,连接在一起。其操作与 Array.toString 和 Array.join 方法相同。 |
Boolean | Boolean 值。 |
Date | 存储的时间是从 1970 年 1 月 1 日午夜开始计的毫秒数 UTC。 |
Function | 函数本身。 |
Number | 数字值。 |
Object | 对象本身。这是默认情况。 |
String | 字符串值。 |
Math and Error objects do not have a valueOf method.
Basically, all JS data types have two methods, valueOf and toString, except null. The two of them solve the problem of javascript value operation and display.
JavaScript’s valueOf() method
The valueOf() method returns the original value of a Boolean object.
Using booleanObject.valueOf(), the return value is the original Boolean value of booleanObject. If the object on which this method is called is not a Boolean, a TypeError exception is thrown.
Related recommendations]
1. Detailed explanation of valueOf method examples in java
2. Between valueOf and toString, (String) in Java The difference between
3. Usage of tostring() and valueof() and the difference between the two
4. valueOf, parseInt in Java , the difference between toString
5. Introduction to object conversion function toString() and valueOf()_