-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathOperators.js
More file actions
176 lines (138 loc) · 3.71 KB
/
Operators.js
File metadata and controls
176 lines (138 loc) · 3.71 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// In Javascript all the operators behavious is same as the Java Operators
// Arithmetic Operators
// plus operator
const a = 20;
const b = 30;
const c = a + b;
// Minus Operator
// Multiplication Operator
// Divide operators
// % Operators
// Post Increment
// Pre Incerement Operators
// Ternary operators
// Logical operators
// Assign Ment Operator
// == and ===
// if you want to compare the value then == operator will give true output if value are same
var foo = "foo";
var number = 123;
if (foo == number) {
console.log("The value are equal");
} else {
console.log("The value are not equal");
}
var name2 = "vishal";
var name1 = "Vishal";
if (name2 == name1) {
console.log("The value are equal");
} else {
console.log("The value are not equal");
}
var name2 = "vishal";
var name1 = "vishal";
if (name2 == name1) {
console.log("The value are equal");
} else {
console.log("The value are not equal");
}
const number2 = 123;
const number1 = 123;
if (number2 == number1) {
console.log("The value are equal");
} else {
console.log("The value are not equal");
}
// ===
// if the value and the datatype are same then the result of this will be true else false
const number4 = 123; // data type is number
const number3 = "123"; // datatype is string
if (number3 == number4) {
console.log("The value are equal ");
} else {
console.log("The value are not equal");
}
if (number3 === number4) {
console.log("The value are equal ");
} else {
console.log("The value are not equal");
}
// Logical Opertor
const data1 = "123";
const data2 = "1231";
const data3 = 1234;
const data4 = {};
const data5 = [];
const data6 = 0;
const data7 = "";
const data8 = true;
if (data1 && data2) {
console.log("Hey i am true");
}
if (data1 && data7) {
console.log("Hey i am true");
} else {
console.log("Hey i am not true");
}
if (data1 && data7) {
console.log("Hey i am true");
} else {
console.log("Hey i am not true");
}
if (data1 && data6) {
console.log("Hey i am true");
} else {
console.log("Hey i am not true");
}
if (data5) {
console.log("I am true");
}
// control structure
// for loop
// for (let i = 0; i < 100; i++) {
// console.log(i);
// }
// let k = 0;
// while (k < 100) {
// console.log(k);
// k++;
// }
// Basic Functions
// normal functions
function printValue() {
console.log("I normal and old stylish functions");
}
// arrow functions
const callMe = () => {
console.log("Hey i am very stylish and arrow functions");
};
function calculateTax(salary, corporateTax, freeLancing, businessTax) {
let totalSalary = 0;
console.log(salary, corporateTax, freeLancing, businessTax);
const corporateTaxValue = (salary * corporateTax) / 100;
const businessTaxValue = (freeLancing * businessTax) / 100;
const totalTax = businessTaxValue + corporateTaxValue;
totalSalary = salary + freeLancing - totalTax;
return totalSalary;
}
const salary = calculateTax(200000, 30, 490000, 20);
console.log("My Salary is: ", salary);
// NAN => Not A number if you will try to do arithmetic operations in another datatype except number this eroor will come
// There one functions to check whether given output is Nan or not that functions is isNaN()
console.log(isNaN(123)); // false
console.log(isNaN(123 + undefined)); // false
// Type coersion
// explicitly , implicitly
//dynamically converting one type into another type is called the type coersion
// explicit => type casting => it is done by the developer
// conversion => to string , to boolean and to Number
// to string
const data = String(123);
const datab = Boolean(123); // true
const datab1 = Boolean(0); // false
const datab3 = Number("123");
// !"vishal" => false
// "vishal" && "name" => boolean => true
// parseInt
// parseFloat
//