-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-fundamentals.js
84 lines (54 loc) · 1.5 KB
/
1-fundamentals.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
/* ---------------------------------------------- */
// 1. How to declare a variable using let and const
const fatherName = 'Arnold';
let season = 'rainy';
season = 'winter';
/* ---------------------------------------------- */
// 2. Conditions
// 6 basic conditions: >, <, ===, !==, <=, >=
// multiple conditions: &&, ||
if (fatherName === 'arnold' || season === 'rainy') {
}
else if (fatherName === 'Arnold') {
}
else {
}
/* ---------------------------------------------- */
// 3. Array Declare
// index,
// length, push,
const numbers = [89, 35, 98, 12];
numbers[0] = 56;
/* ---------------------------------------------- */
// 4. for loop and while loop
// for loop
for (let i = 0; i < numbers.length; i++) {
const number = numbers[i];
confirm.log(number);
}
// while loop
let i = 0;
while (i < numbers.length) {
const number = numbers[i];
console.log(number);
i++;
}
/* ---------------------------------------------- */
// 5. function
function multiply(num1, num2) {
const result = num1 * num2;
return result;
}
const output = multiply(35, 78);
/* ---------------------------------------------- */
// 6. Object
// 3 ways to access property by name
const student = {
name: 'Salib Khan',
age: 32,
movies: ['king khan', 'Dhakar Mastan']
}
const myVariable = 'age';
console.log(student.age); // direct by property No-1
console.log(student['age']);// access via property name string No-2
console.log(student[myVariable]); // access via property name in a variable No-3