Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 15:35:03
Original
1610 people have browsed it

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

1

2

var bool = new Boolean(1);

var myvar = bool.toString();

Copy after login

Output result:

1

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

1

boolean.toString()

Copy after login

Return value

"true" or "false"

valueOf() method
Returns the original value of the Boolean object.
Example

1

2

var bool = new Boolean(0);

var myvar = bool.valueOf();

Copy after login

Output result:

1

false

Copy after login

Grammar

1

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