Basically, all JS data types have the valueOf and toString methods, except null. These two solutions solve the problem of javascript value calculation and display. This article will introduce in detail. If you need them, you can refer to the valueOf Function Method in JavaScript to return the original value of the specified object. Usage:
Object. valueOf () object is a required parameter and is an inherent JScript object.
The valueOf method definition of each inherent JavaScript Object is different.
Object |
Return Value |
Array |
Elements of the array are converted into strings separated by commas (,) and connected together. Its operations are the same as those of Array. toString and Array. join. |
Boolean |
Boolean value. |
Date |
The storage time is the number of milliseconds from midnight, January 1, January 1, 1970 in UTC. |
Function |
Function itself. |
Number |
Numeric value. |
Object |
Object. This is the default situation. |
String |
String value. |
Math and Error objects do not have the valueOf method.
Basically, all JS data types have the valueOf and toString methods, except null. They solve the javascript value calculation and display problems.
ValueOf () method of JavaScript
The valueOf () method returns the original value of a Boolean object.
Use booleanObject. valueOf (). The return value is the original Boolean value of booleanObject. If the object that calls this method is not Boolean, an exception TypeError is thrown.
The Code is as follows: