-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_comparison_operators.js
More file actions
43 lines (34 loc) · 934 Bytes
/
05_comparison_operators.js
File metadata and controls
43 lines (34 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Strict vs loose equality
5 == "5"; // true
5 === "5"; // false
// Type coercion examples
0 == false; // true
1 == true; // true
// Comparison with null/undefined
null == undefined; // true
null === undefined; // false
// String comparisons
"a" < "b"; // true
"Z" < "a"; // true (uppercase letters are "less than" lowercase)
// this is Conditional Statements
function cnt(a, b) {
if (a === b) {
console.log(`${a} is strictly equal to ${b}`);
} else if (a == b) {
console.log(`${a} is loosely equal to ${b}`);
} else if (a > b) {
console.log(`${a} is greater equal to ${b}`);
} else {
console.log(`${a} is less than ${b}`);
}
}
cnt(10, 10); // acording to chnage value
// Comparison Functions
function isAdult(age) {
return age >= 18;
}
function isValidPassowrd(password) {
return password !== "" && password.length >= 8;
}
console.log(isAdult(40));
console.log(isValidPassowrd('55555555'));