-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
118 lines (90 loc) · 1.76 KB
/
code.js
File metadata and controls
118 lines (90 loc) · 1.76 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
/*
let-var-const
*/
//ex1 - let
if (true) {
let a = 40;
console.log(a); //40
}
console.log(a); // undefined
//ex2 - var/let
let a = 50;
let b = 100;
if (true) {
let a = 60;
var c = 10;
console.log(a/c); // 6
console.log(b/c); // 10
}
console.log(c); // 10
console.log(a); // 50
//ex3 const
const a = 50;
a = 60; // shows error. You cannot change the value of const.
const b = "Constant variable";
b = "Assigning new value"; // shows error.
//another example.
const LANGUAGES = ['Js', 'Ruby', 'Python', 'Go'];
LANGUAGES = "Javascript"; // shows error.
LANGUAGES.push('Java'); // Works fine.
console.log(LANGUAGES); // ['Js', 'Ruby', 'Python', 'Go', 'Java']
/*
Default Parameters
*/
//ex1
let sum= (a, b = 10) => {
return a + b;
}
sum(20); // 20 + 10 = 30
sum(20, 50) //70
//ex2
let notWorkingFunction = (a = 10, b) => {
return a + b;
}
notWorkingFunction(20); // NAN. Not gonna work.
notWorkingFunction(20, 30); // 50
/**
* For Of Loop
*/
let iterable= [2,3,4,1];
for (let value of iterable) {
value+=1
console.log(value);
}
/*
Static method
*/
class Square {
static square(n) {
return n * n;
}
}
class Cube extends Square {
static cube(n) {
return super.square(n) * n;
}
}
console.log(Square.square(2)); //4
console.log(Cube.cube(3)); // 27
var tp = new Cube();
console.log(tp.cube());
// 'tp.cube is not a function'.
/**
* Exponentiation infix
*/
Math.pow(7,2);
console.log(7**2);
/**
* padStart() & padEnd()
*/
const data = {
Karachi: '78/50',
Lahore: '88/52',
Peshawar: '58/40'
}
Object.entries(data).map(([city, temp]) => {
console.log(`City: ${city} Weather: ${temp}`)
});
Object.entries(data).map(([city, temp]) => {
console.log(`City: ${city.padEnd(16)} Weather: ${temp}`)
});