-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathJsFunctions1.js
More file actions
132 lines (101 loc) · 2.97 KB
/
JsFunctions1.js
File metadata and controls
132 lines (101 loc) · 2.97 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
// Hoisting of functions will be not covered here
// 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(salary);
let name = "Joe";
const university = "manchester";
function printInfo(info) {
// variable shadowing
var name = "Hey I am done!!!";
console.log(name, info, university);
// functional scope
}
printInfo("hey we are learning functions in deep dive");
// Global object means window
// all the const and let variable will be inside the script tag
{
// block-level scope
}
for (let i = 0; i < 100; i++) {
// block-level-scope
}
if (true) {
// block-level-scope
}
// var is functional scopr variable
// let and const is block-scope variable
// defaul parameters
const defaulCheck = (message = "Hey User Welcome to our platform") => {
console.log(message); // Hey User Welcome to our platform
};
defaulCheck();
const checkValidation = (check) => {
if (check) {
return true;
// return;
// you can return without value
} else {
return "Validation error";
}
};
console.log(checkValidation(true)); //Validation error
const interViewQues = () => {
console.log("hey");
};
console.log(interViewQues());
// always if you not pass anything return statement in the functions it will return the undefined
// if you return empty return type that will also return the undefined
// do not add new line after return
// const jsReturn = () => {
// return
// "vishal";
// }
const jsRetur = () => {
return "hey" + 1234 + "1224" + "tiktikre";
};
// pass function as parameter
const addThreeNumber = (callbackfunc, a, b, c) => {
return callbackfunc(a, b) + c;
};
const add = (a, b) => {
return a + b;
};
let checkdata = addThreeNumber(add, 12, 34, 43);
console.log(checkdata);
const sum = add;
const data = sum(12, 34);
console.log(data);
// you can also return the function from the functions
// higher order functions => functions which return functions is called hoc
const hoc = () => {
return (a, b) => {
return a * b;
};
};
// anonymous function the function which have not name
const callhoc = hoc();
const mul = callhoc(45, 70);
console.log(mul);
// iife immediately invoked functions
(function callmeIme() {
console.log(" i called while declaring");
})();
// function statement or declaration and expression
function decalragtion() {}
// function expression
const expression = () => {};