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

In-depth understanding of valueOf function and toString method

PHP中文网
Release: 2017-05-25 14:48:28
Original
1896 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template