-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13_functions.js
More file actions
142 lines (92 loc) · 3.18 KB
/
Copy path13_functions.js
File metadata and controls
142 lines (92 loc) · 3.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
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
function myName(){
console.log("S")
console.log("U")
console.log("J")
console.log("I")
console.log("T")
}
myName()
// return
/*
S
U
J
I
T
*/
//*************************************************************************************
function addTwoNumber (num1, num2) {
console.log(num1 + num2)
}
addTwoNumber(3, 4) // 7
addTwoNumber(3, "4") // 34
addTwoNumber(3, "a") // 3a
//*************************************************************************************
//creat function with console
function addnumber (number1, number2) {
console.log(number1 + number2)
}
let result = addnumber(5, 3)
console.log(result) // undefined
//*************************************************************************************
//creat function with return
function add (number1, number2) {
let result = number1 + number2
return result
console.log("sujit") // after return in function not valid any type of work
};
let results = add(5, 3)
console.log(results) // 8
//*************************************************************************************
function userMessageAtLoggin (username) {
return `hi ${username} you are logged in`
}
userMessageAtLoggin("Sujit") // no any print in this case
console.log(userMessageAtLoggin("Sujit")) // hi Sujit you are logged in
//*************************************************************************************
// rest operator || sprade
function calculateCartPrice(...value) {
return value
}
console.log(calculateCartPrice(100, 500, 600, 800, 50, 600)) // [ 100, 500, 600, 800, 50, 600 ]
// if
function CartPricecalculate(num1, num2, ...value) {
return value
//
}
console.log(CartPricecalculate(100, 500, 600, 800, 50, 600)) // [ 600, 800, 50, 600 ] because num1 = 100, num2=500 but return only value
//*************************************************************************************
console.log("****************************** From *********************************")
//object pass in function
const object01 = {
userName : "Sujit",
price : 2000
};
function objectinfunction01 (myobject) {
// console.log(`username ${object01.userName} and price is ${object01.price}`)
return `username ${myobject.userName} and price is ${myobject.price}`
}
objectinfunction01(object01) // blank retur because in this function use only return keyword
console.log(objectinfunction01(object01))// username Sujit and price is 2000
// or second option for object pass in function
console.log("****************************** From *********************************")
function objectinfunction02 (anyobject) {
console.log(`username ${anyobject.userName} and price is ${anyobject.price}`)
// return `username ${anyobject.userName} and price is ${anyobject.price}`
}
// console.log(objectinfunction02({
// userName : "Sujit Tomar",
// price : 2000,
// }));
objectinfunction02({
userName : "Sujit Tomar",
price : 1999
});
// array in function
const array01 = [50, 52, 21, 63, 62, 95, 12, 35]
function arrayReturn (getArray) {
return array01[2]
}
console.log(arrayReturn(array01)) // 21
// or you can find this method
console.log (arrayReturn([50, 52, 21, 63, 62, 95, 12, 35])) // 21