-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpression-Operators.js
More file actions
144 lines (100 loc) · 3.44 KB
/
Expression-Operators.js
File metadata and controls
144 lines (100 loc) · 3.44 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
console.log("opearators in js");
let a = 45;
let b = 45;
// Arithmetic operators
// Addtion
console.log("a + b = ", a + b); // a+b = 90
// substraction
console.log("a - b = ", a - b); // a - b = 0
// multiplication
console.log("a * b = ", a * b); //a * b = 2025
// division
console.log("a / b = ", a / b); // a / b = 1
// remainder
console.log("a % b = ", a % b); //a % b = 0
// exponential
console.log("a ** b = ", a ** b); //a ** b = 2.4806364445134117e+74
// post increment
console.log("a++ = ", a++); // a++ = 45
// pre increment
console.log("++a = ", ++a); // ++a = 47
// pre decrement
console.log("--a = ", --a); // --a = 46
// post decrement
console.log("a-- = ", --a); //a-- = 45
// assignment operators
console.log("a = ", a); //a = 45
console.log("a += b", a += b); // a+b = 90
console.log("a -= b", a -= b); // a -= b = 45
console.log("a *= b", a *= b); //a *= b = 2025
console.log("a /= b", a /= b); // a /= b = 45
console.log("a %= b", a %= b); //a %= b = 0
console.log("a **= b", a **= b); //a **= b = 0
// Comparison Operators
let x = 10;
let y = "10";
// Equal to
console.log("x == y: ", x == y); // Output: true
// Not equal to
console.log("x != y: ", x != y); // Output: false
// Strict equal to
console.log("x === y: ", x === y); // Output: false
// triple equal to is restricted operator its also check type
// Strict not equal to
console.log("x !== y: ", x !== y); // Output: true
// Greater than
console.log("x > y: ", x > y); // Output: false
// Less than
console.log("x < y: ", x < y); // Output: false
// Greater than or equal to
console.log("x >= y: ", x >= y); // Output: true
// Less than or equal to
console.log("x <= y: ", x <= y); // Output: true
// Logical Operators
let p = true;
let q = false
// Logical AND
console.log("p && q: ", p && q); // Output: false
// Logical OR
console.log("p || q: ", p || q); // Output: true
// Logical NOT
console.log("!p: ", !p); // Output: false
console.log("!q: ", !q); // Output: true
// Bitwise Operators
let m = 5; // 0101 in binary
let n = 3; // 0011 in binary
// Bitwise AND
console.log("m & n: ", m & n); // Output: 1 (0001)
// Bitwise OR
console.log("m | n: ", m | n); // Output: 7 (0111)
// Bitwise XOR
console.log("m ^ n: ", m ^ n); // Output: 6 (0110)
// Bitwise NOT
console.log("~m: ", ~m); // Output: -6 (inverts bits of 5)
// Left Shift
console.log("m << 1: ", m << 1); // Output: 10 (shifts bits left by 1)
// Right Shift
console.log("m >> 1: ", m >> 1); // Output: 2 (shifts bits right by 1)
// Zero Fill Right Shift
console.log("m >>> 1: ", m >>> 1); // Output: 2 (shifts right with zero fill)
// Ternary Operator
let age = 18;
let canVote = (age >= 18) ? "Yes, you can vote." : "No, you cannot vote.";
console.log(canVote); // Output: Yes, you can vote.
// Instanceof Operator
function Car(make, model) {
this.make = make;
this.model = model;
}
let myCar = new Car("Toyota", "Corolla");
console.log("myCar instanceof Car: ", myCar instanceof Car); // Output: true
console.log("myCar instanceof Object: ", myCar instanceof Object); // Output: true
console.log("myCar instanceof Array: ", myCar instanceof Array); // Output: false
// Delete Operator
let obj = {
name: "Saad",
age: 21
};
console.log("Before delete: ", obj); // Output: { name: 'Saad', age: 21 }
delete obj.age;
console.log("After delete: ", obj); // Output: { name: 'Saad' }