In computer science, a boolean is a logical data type that can have only the values true
or false
. A boolean is how a programming language lets you represent true and false. Without the ability to represent boolean values a number of things in a language would no longer work. For example, in JavaScript, an if statement's conditional has to resolve to a boolean value for it to execute at all. Without the boolean conditional, a JavaScript for loop would never know when to stop looping.
***JavaScript if Statement*** if(boolean conditional) { //coding } if(true) { console.log("boolean conditional resolved to true"); } else { console.log("boolean conditional resolved to false"); } ***JavaScript for Loop*** for(control variable; boolean conditional; counter) { //coding } for(var i=0; i<4; i++) { console.log("I print only when the boolean conditional is true"); }
Learn more
General knowledge
- Boolean on Wikipedia
Technical reference
- The JavaScript global object:
Boolean
- JavaScript data types and data structures
Document Tags and Contributors
Tags:
Contributors to this page:
___,
rajkishor09,
SnoopyRules,
ktajpuri,
x2357,
klez,
Andrew_Pfeiffer,
Jeremie,
fscholz,
ajinkya_p
Last updated by:
___,