Home  >  Article  >  Web Front-end  >  Example parsing the toString() method and valueOf() method of JS Boolean object_Basic knowledge

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

WBOY
WBOYOriginal
2016-05-16 15:35:031517browse

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

Output result:

true

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

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

Output result:

false

Grammar

boolean.valueOf()

Return value

"true" or "false"

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