+ 1
hello guys can someone give me an example in using Boolean in programme
2 Respostas
+ 2
Very often, in programming, you will need a data type that can only have one of two values, like
YES / NO
ON / OFF
TRUE / FALSE
JS
Boolean(10 > 9) // returns true
Or even easier:
(10 > 9) // also returns true
10 > 9 // also returns true
Boolean.prototype.myColor = function() {
if (this.valueOf() == true) {
return "green";
} else {
return = "red";
}
};
var a = true;
var b = a.myColor();
The value of b is now:
green
0
<!-- true or false is a boolean value -->