What is booleans in java script for? in what use?


#1



Replace this line with your code.


#2

Booleans can have one of two values: true or false.
They represent something you're unsure of and they're important for decision making.
If you for instance want to check if an age a user entered is larger than 18 (you're unsure of it at first), you can set a boolean equal to age > 18, which will return either true or false depending upon the age.

You can then control the flow of the program accordingly. For instance:

var age = prompt('What is your age?'); // unknown
if(age > 18) { // a boolean
    console.log("You're an adult");
} else {
    console.log("You're still a child");
}