-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.js
325 lines (249 loc) · 8.46 KB
/
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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// Operators in Javascript
// Used to perform some operation on data
// 1. Arithmetic Operators
// let a = 65;
// let b = 7;
// let c = 9;
// let assign = ("a = ", a, "& b = ",b);
// let sum = (a+b+c);
// let substract = (a-b-c);
// let division = (a/7);
// let multiple = (a*b*c);
// console.log("a + b + c =" + a + b + c);
// console.log("sum is " + sum);
// console.log("a-b-c = " + [substract]);
// console.log("substraction will be = ", a-b-c);
// console.log(division);
// console.log("Substraction will be = " + [division]);
// console.log(multiple);
// console.log("Multiplication will be = " + [multiple]);
// 2. The Remainder or Modulus Operators in Javascript
//The remainder or Modulus (%) operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.
//Sign(%) or %
// let remain = (a % c);
// console.log(remain); //Output will be 2 as remain when 65/9 gives remainder : 2
// console.log("a % c = " + [remain]);
// 3. The Exponentiation Operators
// let d = 2;
// let e = 3;
// let Exponentiation = (d**e);
// console.log("Exponentiation will be = " + [Exponentiation]);
// console.log("Exponentiations of d ** e = " + d ** e);
// 4. Unary Operators
// 4.1 Increment Operators
// The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
// Sign (a ++ b)
// let f = 5;
// let g = 6;
// console.log("f = " + f , " & g = " + g);
// f++;
// // or f = f+1;
// g++;
// console.log("f = " + f )
// //console.log("f = " + [f]);
// console.log("g = " + g );
//console.log("g = " + [g]);
// 4.2 Decrement Operators
// The decrement (--) operator decrements (subtracts one from) its operand and returns the value before or after the decrement, depending on where the operator is placed.
// let h = 11;
// let i = 14;
// console.log("We have h = " + h , "i = " + i);
//h = h-1;
// h--; //post decrement
// i--; //post decrement
//pre increment will be = ++h or ++i
// console.log("Decreament of h will be " + h);
// console.log("Decreament of i will be " + i);
// 5. Assignment Operators :
// The assignment operator is completely different from the equals (=) sign used as syntactic separators in other locations, which include:
// Example : = , += , -= , *= , %= , **=
// 5.1 : for increment assignment operators
// let a = 5;
// let b = 2;
// a += 4; //or write as a = a + 4;
// b += 3; //or write as b = b +3;
// console.log("incrememt for a is = ", a );
// console.log("increment for b is = ", b);
// 5.2 : for decrement assignment operators
// let c = 6;
// let d = 9;
// c -= 3;
// d -= 9;
// console.log("decrement for c is = ", c);
// console.log("decrement for d is = ", d);
// 5.3 : for division assignment operators
// let e = 6;
// let f = 9;
// e /= 3;
// f /= 9;
// console.log("division results of e is = ", e);
// console.log("division results of f is = ", f);
//5.4 : for multiplications assignment operators
// let g = 5;
// let h = 10;
// g *= 2;
// h *= 2;
// console.log("multiplication results of g is = ", g);
// console.log("multiplication results of h is = ", h);
// 5.5 : for modulus assignment operators
// let i = 65;
// let j = 127;
// i %= 9;
// j %= 15;
// console.log("modulus results of i is = ", i);
// console.log("modulus results of j is = ", j);
// 5.6 : for Exponential assignment Operators
// let k = 4;
// let l = 7;
// k **= 3;
// l **= 2;
// console.log("Exponential results of k is = ", k);
// console.log("Exponential results of l is = ", l);
// 6 : Comparison Operators
//Comparison operators are used in logical statements to determine equality or difference between variables or values.
//signs = ( == , ==== , != , !== , > , < , >= , <= )
// 6.1 : == equal to comparison Operators
// false :
// let a = 5;
// let b = 2;
// console.log("5 == 2", a == b);
// Output will be : 5 == 2 false it is a boolean checker from == is true or false.
// True :
// let c = 9;
// let d = 9;
// console.log("9 == 9", c == d);
// Output will be : 9 == 9 true
// 6.2 : === equal value and equal type it is strict version.
// (===) is also a boolean Operators but it checks value also but with type of input
//As an Example from only with equal to (==) operators :
// let e = 15;
// let f = "15";
// console.log("15 == 15", e == f);
// There is exception of equal to operators that it doesn't check the types of input as string or what !
// Therefore need of === equal value and equal type :
// let e = 25;
// let f = "25"; //it is string not number
// console.log("e === f", e === f);
// Output will be : e === f false as type of input is string & other is (e = 25 is number )
// let g = 45;
// let h = 45;
// console.log("g === h", g === h);
// Output will show : g === h true as value & type of input (both is same as number) so that it show true
// 6.3 : Comparison Operators for > greater than or < less than | it is also a boolean true or false checker
// For greater than
// For false:
// let i = 23;
// let j = 27;
// console.log("i > j", i > j);
//Output : i > j false
// For true:
// let k = 56;
// let l = 45;
// console.log("k > l", k > l);
//Output : k > l true
// For less than
// For false
// let m = 52;
// let n = 51;
// console.log("m < n", m < n);
//Output : m < n false
// For true
// let o = 56;
// let p = 59;
// console.log("o < p", o < p);
//Output : o < p true
// 6.4 : Comparison Operators for : >= greater than or equal to & <= less than or equal to
//>= greater than or equal to
//false
// let q = 65;
// let r = 79;
// console.log("q >= r", q >= r);
//Output : q >= r false
//True
// let s = 79;
// let t = 65;
// console.log("s >= t", s >= t);
//Output : s >= t true
//Check for equal to
// let u = 89;
// let v = 89;
// console.log("u >= v", u >= v);
//Output true because of it check equal to or : s >= t true
//<= less than or equal to
//false
// let less = 45;
// let big = 39;
// console.log("less <= big", less <= big);
//Output will be : less <= big false
//True
// let other = 34;
// let another = 39;
// console.log("other <= another", other <= another);
//Output will be : other <= another true
// 6.5 : != not equal & !== not equal value or not equal type , comparison checker
//!= not equal
//false
// let ap = 33;
// let bp = 33;
// console.log("ap != bp ", ap != bp);
//Output will be : != not equal because of 33 is equal to 33 , not verify the statement of != too.
//True
// let ac = 34;
// let bc = 35;
// console.log("ac != bc", ac != bc);
//Output will be : ac != bc true
//!== not equal value or not equal type
//false
// let xb = 55;
// let xc = 55;
// console.log("xb !== xc", xb !== xc);
// //True
// let cb = 55;
// let cc = "55";
// console.log("cd !== cc", cb !== cc);
//Output will be : cd !== cc true as it not equal to also with input type but qual to value
// 6.6 : Logical Operators
//Logical operators are used to determine the logic between variables or values that both should be correct
//sign : && , || , !
//&& Operators
//true
// let xa = 6;
// let xd = 3;
// console.log("xa && xd = ",xa < 10 && xd > 1);
//Output will be : true because both logic is true
//false
// let za = 6;
// let zd = 3;
// console.log("za && zd = ",za < 2 && zd > 1);
//Output will be : false
// || Operators
//it consits for either any one statement goes true than print true
// let bf = 2;
// let gf = 4;
// console.log("bf || gf = ",bf == 2 || gf == 5);
//Output will be : true
// ! Operators
let an = 6;
let bn = 3;
// Now in console we will check the conditions.
// The satisfied (true) condition will output as false because of the ! operator
// and the unsatisfied (false) condition will output as true.
// console.log("an ! bn = ",! (an === bn) + "<br>" + ! (an > bn));
//Output will be : an ! bn = true<br>false
//or you can make condition with let
//Like
// let conditions1 = an > bn;
// let conditions2 = an > 3;
// console.log("conditions1 ! conditions2 = ", ! conditions1 + "<br>" + conditions2 );
//Ternary Operators :
//Three Operands exists in ternary Operators In javascript
//The conditional (ternary) operator is the only JavaScript operator that takes three operands:
//Three Operands such as : conditions ? true output : false output
//____?___:____false output
//if conditions true as in left side then print ___: statement , else if statement is false then print :_____ statement
//Example 1 :
// let age = 15;
// let result = age >= 18 ? "adult" : "children";
//or can be written as : age >= 18 ? console.log("adult") : console.log("children");
// console.log(result);
//simpler & compact if-else