-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasics.js
76 lines (60 loc) · 1.53 KB
/
basics.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
// TODO: Basic js topics (variables, types, operators, conditionals)
// variables are loosely type
// let a = 5
// console.log(a)
// a = 'hi'
// console.log(a)
// * Infinity type
// let a = 1 / 0
// console.log(a)
// console.log(1/Infinity)
// * max value of number
// console.log(Number.MAX_VALUE)
// * typeof operator
// let a = 5
// console.log(typeof a)
// console.log(typeof NaN);
// console.log(typeof Infinity);
// console.log(typeof parseInt("a"))
// * Arithmetic Operators
// console.log(10+2);
// -,*,/,%, +=, -=, *=, /=, ++, --
// * Comparison Operators
// >,<,>=,<=,!=,==,===,!==
// == vs ===
// 1 == '1' => true (Type Coercion)
// 1 === '1' => false (Without Type Coercion)
// 1 === 1 => true (Without Type Coercion)
// * Logical operations
// &&, ||, ! (follow short circuit evaluation eg. in && if first false second doesn't executed)
// * Bitwise operators
// >>, <<, &, |, >>>
// * Type Coercion
// console.log('hi'+2); // hi2
// console.log('1'+1); // 11
// console.log('1'-1); // 0
// + -> string concatination
// -.*,/,>,<,... -> type conversion to number
// * Conditionals
// var a = 0;
// if (a > 0) {
// console.log('Positive');
// }else if (a < 0) {
// console.log('Negative');
// }else{
// console.log('Zero');
// }
// in condition 0,"",undefined variables, null means false everyting else will give true
// console.log(null == undefined); => true
// * Loops
var i = 1
while(i<5) {
console.log(i);
}
for(i=1; i <= 5; i++) {
console.log(i);
}
do{
console.log(i);
i++
}while(i<=5)