0
Q:

javascript logical and operator

//The OR operator in Javascript is 2 verticals lines: ||

//Example
var booleanOne = true;
var booleanTwo = false;

if(booleanOne || booleanTwo) {
	//At least one boolean is true -> code excuted
}
11
// There are 3 Javascript Logical Operators
// || (OR)
// && (AND)
// ! (NOT)

if (a || b) {
	console.log("I will run if either a or b are true");
}

if (a && b) {
	console.log("I will run, if and only if a and b are both true");
}

if (!a) {
	console.log("I will only run if a is false");
}

if (a) {
	console.log("I will only run if a is true");
}
1
var hungry=true;
var slow=true;
var anxious=true;

//&& means and
if(hungry && slow && anxious){ 
	var cause="weed";
}
3
//& (bitwise AND) operator
console.log(5 & 13); //outout: 5
/*
5  = 0101 (base 2)
13 = 1101 (base 2)
//AND every bit together from both numbers
+----+
|0101|
|1101|
+----+
|0101|
+----+
0101 = 5 (base 10)
*/
0
if(booleanOne && booleanTwo) {
	//Both booleanOne and booleanTwo are true here
}
-2

New to Communities?

Join the community