Q:

js comparison operators

//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
//x = 5

operator  |	example	 |	output  |	explination

==			x == 8		false		equal to
			x == 5		true
			x == "5"	true

===			x === 5		true		equal value and type
			x === "5"	false

!=			x != 8		true		not equal

!==			x !== 5		false		not equal value or not equal type
			x !== "5"	true
			x !== 8		true

>			x > 8		false		greater than

<			x < 8		true		less than

>=			x >= 8		false		greater than or equal to

<=			x <= 8		true		less than or equal to
7
true != true // => false
0
//Equal to or more than
a >= b
//Equal to or less than
a <= b
2
//&& returns true if both values are true
//or returns the second argument if the first is true
var a = true
var b = ""
var c = 1

true && "" //""
"" && 1 //""
false && 5 //false
2
0 !== "0"
0 !== 0
1
//& (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

New to Communities?

Join the community