-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperator.js
315 lines (206 loc) · 7.34 KB
/
operator.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
/* Operators
expression result in a value.
//Example
1 + 2
Here, 1 and 2 is Operands and (+) is Operator.
*Operands in Programming languages are called ARGUMENTS.*/
//1.Arithemetic Operators
/* *Addition(Right to Left)
*Substraction(Right to left)
*division(left to right)
*Multiplication(left to right)
*Remainder(%)(left to right)
*Unary Negation
-if y =10 then -y =-10(right to left)
*Unary Plus
-if y =-10 then y =10(right to left)
*Pre-Increment(++X)
-increment value by one then evaluates to new value(right to left)
*Post-Increment(X++)
-increment value by one but evaluates the value of y before increment(right to left)
*Pre-decrement(right to left)
*Post-decrement(right to left)*/
//Pre and Post Increment
/*let j, x =5;
j =++x;
console.log(j + " " + "with pre-increment");*/ //result wil be 6
/*let j, x =5;
j =x++;
console.log(j + " " + "with post-increment");*/ //result will be 5.
//2.Comparison Operator(Strict equality, Abstract equality and Relational)
/*
*less then(<)(left to right)
*greater then(>)(left to right)
*less then or equal to(<=)(left to right)
*greater then or equal to(>=)(left to right)
*/
//1.Strict equality types (refers to the same object OR they are same types OR have the same value)(===)(!==)
//2.Abstract equality(==)(!=)(refers to the same object OR have the same value)
//Example Strict and Abstract
/*let x =10, str ="10";
console.log(x==str);
//gets true
console.log(x===str);*/
//gets false because they dont have the same data types
//Converting str into number:
/*let x =10, str = "10";
console.log(x===Number(str));*/
//3.Logical Operators
/*
*AND(&&)
*OR(||)
*NOT(!)
*/
//a.AND(&&)
/*
-used for boolean operations on two values.
-returs true if and only if its first and second Operand are true.
*/
//Example
/*
let x =10, y =10;
if (x===10&&y===10){
console.log("true");
}else{
console.log("false");
}*/
//Returs True
/*
let x =10, y =10;
if (x===10&&y===5){
console.log("true");
}else{
console.log("false");
}*/
//Returs False
//b.OR(||)
/*
-performs boolean expressions on two relational values.
-returs true if one or both operands are true.*/
//Example
/*
let x =10,
y =10;
if(x===10||y===10){
console.log("true")
}else{
console.log("false");
}*/
//Returs True
/*
let x =10,
y =10;
if(x===10||y===5){
console.log("true")
}else{
console.log("false");
}*/
//Returs True Again
//c.NOT(!)
/*
-Unary operator
-it is placed before the single operand.*/
/*
-used to invert the boolean.
if X =True;
use ! i.e
!x =False;
*/
//4. Assignment Operator(=)
// let x =5
/*
-used with arithmetic addition
x =x+y;*/
//Example
/*
let x =10,
y =3;
x +=y; //adds
console.log(x);*/
//prints 13
/*
let x =10,
y =3;
x -=y; //subtract
console.log(x);*/
//prints 7
//for multiplication(x*=y;)
//for division(x/=y;)
//for remainder(x%=y;)
//for AND(x&=y;)
//for OR(x|=y;)
//5.typeof operator(typeof)
/* 7 data types:-
1.undefined
2.null
3.boolean
4.number
5.string
6.symbol
7.object
*/
//Example
/*
console.log(typeof 1);
//retur number
console.log(typeof "vc");
//return string
console.log(typeof null);
//return object
console.log(typeof true);
//return boolean
console.log(typeof function(){});
//retur function
*/
//6.Destructing assignment operator
//Example
/*
\const obj = {a:1, b:2, c:3, e:5};
//destructing assignment operator
const {a, b, c, d, e} = obj;
//ptint variables
console.log(a);
console.log(b);
//but
console.log(d);*/ //undefined
//example
/*
const arry =[1, 2, 3];
//destructing assignment
const [a, b, ...rest] =arry;
console.log(a);
console.log(b);
console.log(rest);
//Using spread operator(...)
console.log(rest);*/
//7.destructuring arguments(arguments are identifiers)
//example
/*
const bed ={ //declare object
w1: "blanket",
w2: "cusion",
w3: "pillow"
};
//create function
function getdata({w1, w2, w3}){
return `${w1} ${w2} ${w3}`;
}
console.log(getdata(bed));
*/
//8. Call() Method
//example
/*
function magic(){
return `welcome, to ${this.name};`
}
//create two objects
const obj1 ={name: "full"};
const obj2 ={name: "half"};
//call function
console.log(magic());
//without call method..
//prints undefined
//with call method()
console.log(magic.call(obj1));
console.log(magic.call(obj2));
*/