-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19. Functions & parameters.js
107 lines (75 loc) · 1.98 KB
/
19. Functions & parameters.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
function sayMyName() {
console.log("T");
console.log("A");
console.log("M");
console.log("I");
console.log("M");
}
// console.log(sayMyName()); // [H I T E S H], undefined
// OUTPUT:
// T
// A
// M
// I
// M
// undefined
// sayMyName(); // // [H I T E S H]
// OUTPUT:
// T
// A
// M
// I
// M
function addTwoNumbers(number1, number2){
console.log(number1 + number2);
}
// addTwoNumbers(5, 6); // 11
function addTwoNumbers2(num1, num2) {
let result = num1 + num2;
console.log(result);
return result;
}
// addTwoNumbers2(10, 15); // 25
// console.log(addTwoNumbers2(10, 10));
// output:
// 20
// 20
function name1(username = "Tamim") {
if (!username) { // (username === undefined)
console.log("Please enter your username");
return;
}
return console.log(`${username} just logged in`);
}
// name1("Hello"); // Hello just logged in
// name1("") // Please enter your username
// name1(); // Tamim just logged in
function calculateCartPrice(val1, val2, ...num1){
return num1;
}
// console.log(calculateCartPrice(200, 400, 500, 2000)); // [ 500, 2000 ]
const user = {
username: "tamim",
price: 200,
}
function handleObjects(anyObjects) {
console.log(`Username is ${anyObjects.username} & price is ${anyObjects.price}`);
}
// handleObjects(user); // Username is tamim & price is 200
// handleObjects({
// username: "Hello", // Username is Hello & price is 200
// price: 200,
// })
const myNewArray = [200, 400, 100, 600]
function returnSecondValue(getArray){
return getArray[2]
}
// console.log(returnSecondValue(myNewArray)); // 100
// console.log(returnSecondValue([200, 400, 500, 1000])); // 500
function car(val1, val2, ...num) {
return num;
}
// console.log(car[100, 200, 300, 400, 500]); // undefined
// console.log(returnSecondValue(myNewArray)); // 100
// console.log(returnSecondValue([200, 400, 500, 1000])); // 500
// << Js is 0 based index >>