-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathprogram.js
More file actions
58 lines (41 loc) · 1 KB
/
Copy pathprogram.js
File metadata and controls
58 lines (41 loc) · 1 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
// string concatenation
let a = 2 + 2 + '1';
console.log(a); // 41
let b = '1' + 2 + 2;
console.log(b); // 122
// unary conversion using +
let c = "";
console.log(+c); // 0
let val1 = "2";
let val2 = "3";
console.log(+val1 + +val2); // 5
console.log(+false);
// chaining assignment
let x,y,z;
x = y = z = 5;
console.log(x,y,z); // 5 5 5
// increment/decrement
let counter = 5;
console.log(++counter); // 6
console.log(counter++); //6
console.log(counter); //7
console.log(--counter); // 6
console.log(counter--); //6
console.log(counter); //5
//comma operators
let comma = (1+2, 3+4);
console.log(comma); // 7 (returns only the last result)
let sym1 = Symbol("id");
let sym2 = Symbol.for("id"); // if doesn't exist creats new one
let str = "Hello \rworls";
console.log(str)
// Example to find common elements between 2 arrays.
let ar1 = [1,2,3,4,5];
let ar2 = [4,5,6];
let ar = ar1.filter(function(val) {
for(let ke of this) {
if (val == ke)
return true;
}
}, ar2);
console.log( ar );