forked from faisal2410/js_basic_ostad_b3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8_comparison_operators.js
92 lines (59 loc) · 2.58 KB
/
8_comparison_operators.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// In JavaScript, comparison operators are used to compare values and return a boolean(true / false) value based on the comparison result.
// Here are some commonly used comparison operators in JavaScript:
// Equal to(==): This operator checks if two values are equal.If they are, it returns true, otherwise false.
// 👀👀
console.log(5 == 5); // true
console.log('5' == 5); // true
console.log(5 == 6); // false
// Strict equal to(===): This operator checks if two values are equal and of the same type.If they are, it returns true, otherwise false.
// 👀👀
console.log(5 === 5); // true
console.log('5' === 5); // false
console.log(5 === 6); // false
// Not equal to(!=): This operator checks if two values are not equal.If they are not, it returns true, otherwise false.
// 👀👀
console.log(5 != 5); // false
console.log('5' != 5); // false
console.log(5 != 6); // true
// Strict not equal to(!==): This operator checks if two values are not equal and of the same type.If they are not, it returns true, otherwise false.
// 👀👀
console.log(5 !== 5); // false
console.log('5' !== 5); // true
console.log(5 !== 6); // true
// Greater than(>): This operator checks if the first value is greater than the second value.If it is, it returns true, otherwise false.
// 👀👀
console.log(5 > 3); // true
console.log(5 > 5); // false
console.log(5 > 7); // false
// Less than(<): This operator checks if the first value is less than the second value.If it is, it returns true, otherwise false.
// 👀👀
console.log(5 < 7); // true
console.log(5 < 5); // false
console.log(5 < 3); // false
// Greater than or equal to(>=): This operator checks if the first value is greater than or equal to the second value.If it is, it returns true, otherwise false.
// 👀👀
console.log(5 >= 3); // true
console.log(5 >= 5); // true
console.log(5 >= 7); // false
// Less than or equal to(<=): This operator checks if the first value is less than or equal to the second value.If it is, it returns true, otherwise false.
// 👀👀
console.log(5 <= 7); // true
console.log(5 <= 5); // true
console.log(5 <= 3); // false
function compareNumbers(num1, num2) {
let result = "";
if (num1 > num2) {
result = `${num1} is greater than ${num2}`;
} else if (num1 < num2) {
result = `${num1} is less than ${num2}`;
} else {
result = `${num1} is equal to ${num2}`;
}
return result;
}
console.log(compareNumbers(5, 10));
// Output: "5 is less than 10"
console.log(compareNumbers(10, 5));
// Output: "10 is greater than 5"
console.log(compareNumbers(5, 5));
// Output: "5 is equal to 5"