The if statement runs code only if the boolean it's relying on is true
. It's like saying, if something is true, then do this.
"Hello!"
will display in the console if we set the boolean value to true
.
if (true) {
console.log("Hello");
}
But what if we want to skip code? We use false
instead.
By setting the value to false
, we'll avoid displaying "Hello!"
.
if (false) {
console.log("Hello!");
}