Home > Web Front-end > JS Tutorial > body text

Example parsing the toString() method and valueOf() method of JS Boolean object_Basic knowledge

WBOY
Release: 2016-05-16 15:35:03
Original
1516 people have browsed it

toString() method
Convert Boolean value to string and return the result.
Example
Convert boolean to string:

var bool = new Boolean(1);
var myvar = bool.toString();
Copy after login

Output result:

true
Copy after login

Definition and usage
The toString() method converts a logical value to a string and returns the result.
Note: JavaScript will automatically call this method when you need to convert a Boolean object into a string.
Grammar

boolean.toString()
Copy after login

Return value

"true" or "false"

valueOf() method
Returns the original value of the Boolean object.
Example
var bool = new Boolean(0);
var myvar = bool.valueOf();
Copy after login

Output result:

false
Copy after login

Grammar

boolean.valueOf()
Copy after login

Return value

"true" or "false"

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!