Home  >  Article  >  Web Front-end  >  valueOf() function and toString() function usage

valueOf() function and toString() function usage

巴扎黑
巴扎黑Original
2017-07-22 15:22:501241browse

valueOf(): If any primitive value exists, returns the primitive value that best fits the object type.

toString(): Return the original value of the object in string form.

This The two methods are generally called implicitly by JS to meet different operating conditions.


Give me an example: Look at the picture ( Don't worry about the two undefined), the colors of true returned by the two methods are different! Because toString() returns a string, and valueOf() returns the original value.


##END


The above is the detailed content of valueOf() function and toString() function usage. For more information, please follow other related articles on the PHP Chinese website!

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