- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the purpose of new Boolean() in JavaScript?
The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.
The new Boolean() is used to create a new object. Use the following syntax to create a boolean object.
var val = new Boolean(value);
Example
Let us see an example of toString() method, which returns a string of either "true" or "false" depending upon the value of the object −
<html> <head> <title>JavaScript toString() Method</title> </head> <body> <script> var flag = new Boolean(false); document.write( "flag.toString = " + flag.toString() ); </script> </body> </html>
Advertisements