-
Notifications
You must be signed in to change notification settings - Fork 4
/
relevel.js
128 lines (114 loc) · 3.9 KB
/
relevel.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
/**
// variables
// var a = 2
// let a = 2
// const a = 2
// Difference Between var, let, const
// var ----> Declare it multiple times but behind the scenes it will be only once, and rest will just assignment.
// Global and Function Scope.
// let -----> Cannot be declared more than once
// Block Scope.
// const ----> Cannot be declared more than once and cannot be reassiagned also.
// Block Scope.
//types of variables
// 1. Number - 2, 3, 4, 0...., NaN, +Infinity, -Infinity
// 2. String - '', "", ``
// 3. boolean - true/false
// 4. object - null, ex: let a=null
// 5. undefined - ex: let a
// 6. BigInt - ignore
// 7. symbol - ignore
// naming convention of variables
// 1. contains letter, digits, _, $
// 2. can start with _, $, letter (digits is not allowed).
// 3. keywords cannot be used as variable names.
// keywords
// words that is reserved by js, ex: var, let, const, function...
//operators
// 1. arithmetic
// + -> addition and concatenation
// - -> subtraction
// / -> Division
// * -> multiply
// % -> modulus (remainder operator).
// 2. relational
// < -> lesser than
// > -> greater than
// <= -> lesser than or equal to
// >= -> greater than or equal to
// NOTES: These operators will only return boolean values, and used incase of condition checking.
// 3. Increment/Decrement
// a++ -> post-Increment -> pehle istemaal phir viswaas kro -> first use then increment
// var b = a++
// b = a
// a = a+1;
// ++a -> pre-Increment -> pehle viswaas kre phir istemaal kre -> first incement then use.
// var b = ++a
// a = a+1
// b = a
// a-- -> post-Decrement
// --a -> pre-Decrement
// 4. Assisgment
// =
// var a = 2
// +=
// a+=2 ------> a = a+2
// -=
// *=
// /=
// 5. Equality
// ==
// if required, first Type Coersion then check
// 2 == '2' --> true, because number 2 will be converted to string.
// ===
// checks datatype and value too, no type coercion
// 2 === '2' --> false, because datatype of both values are different.
// 6. unary
// + ----> converts string to number
// ! -----> true to false , false to true
// Flasy Values -> null, undefined, "", 0, false, 0n, NaN
// 7. ternary
// ? and : ----> ([condition]) ? (lines to be returned or executed if condtion matches) : (lines to be returned or executed if condtion doesn't match)
// condition statements
// 1. if/else
// syntax:
// if([condition1]) {
// lines to execute if condition1 matches
//} else if([condition2]) {
// lines to execute if condition2 matches
//} else {
// lines to execute if none of the above conditions matched.
//}
// 2. switch
// syntax:
// switch([variable to be checked with cases]) {
case 1: {
lines to be executed if 1st case is true
break; ----> this needs to be applied so as to break switch statement, otherwise it will
execute all the other cases wihout checking the case condition.
}
case 2: {
}
case 3: {
}
default: {
incase other cases condition is not met.
}
}
Iterative statements
1. while --> while loop is to execute repetative block of code til the condition fail.
syntax:
while([condition]) {
// lines to execute till condition matches.
}
2. for --> for loop is just an extension of while loop in which initilaiztion, condition and incemeent/decrement will be
in single line
syntax:
for([intialization]:[condition]:[incemeent/decrement]) {
// lines to execute till condition matches.
}
*/
var a = 2
var b = 3
var result = a+b
console.log(`result is ${result}`)