1Javascript Comparison Operators
2== Equal to
3=== Equal value and equal type
4!= Not equal
5!== Not equal value or not equal type
6> Greater than
7< Less than
8>= Greater than or equal to
9<= Less than or equal to
10? Ternary operator
11
1var a = 2;
2var b = 5;
3var c = 10;
4
5if (a === 3 || a === 2) {
6 console.log("TRUE");
7} else {console.log("FALSE");}
8if (a === 4 || b === 3 || c === 11) {
9 console.log("TRUE");
10} else {console.log("FALSE");}
11if (b === 5 || c != 10) {
12 console.log("TRUE");
13} else {console.log("FALSE");}
14
15/* Output:
16TRUE
17FALSE
18TRUE
19*/
1//|| is the or operator in JavaScript
2if(a == 1 || b != 'value'){
3 yourFunction();
4}
1const num = 6;
2if (num <= 4 || num <= 8) {
3 console.log('true')
4} else {
5 console.log('false')
6}
7//Expected output:true
1// There are 3 Javascript Logical Operators
2// || (OR)
3// && (AND)
4// ! (NOT)
5
6if (a || b) {
7 console.log("I will run if either a or b are true");
8}
9
10if (a && b) {
11 console.log("I will run, if and only if a and b are both true");
12}
13
14if (!a) {
15 console.log("I will only run if a is false");
16}
17
18if (a) {
19 console.log("I will only run if a is true");
20}