Home  >  Article  >  Web Front-end  >  In-depth understanding of valueOf function and toString method

In-depth understanding of valueOf function and toString method

PHP中文网
PHP中文网Original
2017-05-25 14:48:281815browse

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()_

6.Use toString() The method returns the time as a string

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn