-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.js
More file actions
57 lines (42 loc) · 1.18 KB
/
Copy pathfunction.js
File metadata and controls
57 lines (42 loc) · 1.18 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
function printName(name) {
console.log('name is %s', name);
console.log(`name is ${name}`);
}
printName('arvind');
function addTwoNum(num1, num2) {
return num1 + num2;
}
console.log(addTwoNum(12, 23));
function printer(value) {
console.log(`value: ${value}`);
}
function printerWithMessage(value) {
console.log(`hello ${value}! welcome to js tutorial`);
}
// printGoodName is func that take another func as a param
function printGoodName(name, fn) {
fn(name);
}
printGoodName('anurag', printer);
printGoodName('anurag', printerWithMessage);
// a function returns another function
function num1(a) {
return function (b) {
return a + b;
}
}
let func1 = num1(10);
console.log(func1(20));
// arrow function
const namePrinter = function (name) {
console.log(name);
};
const namePrinterArrow = name => console.log(name); // no need of args parenthesis and function block
const sumTwo = (num1, num2) => num1 + num2; // no need of return keyword
const calProductDiscount = (price, disPercentage) => {
const discount = price * disPercentage / 100;
return price - discount;
};
namePrinterArrow('arvind');
console.log(sumTwo(21, 23));
console.log(calProductDiscount(100, 10));