-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_functions.js
More file actions
76 lines (55 loc) · 1.8 KB
/
01_functions.js
File metadata and controls
76 lines (55 loc) · 1.8 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
function sayMyName() {
console.log("s");
console.log("a");
console.log("n");
console.log("d");
console.log("y");
}
// sayMyName()
// function addTwoNumbers(num1, num2) {
// console.log(num1 + num2);
// }
// addTwoNumbers(4, 6);
// const result = addTwoNumbers(4, 6);
// console.log("Result: ", result);
function addTwoNumbers(num1, num2) {
// let result = num1 + num2
// return result
// OR
return num1 + num2
}
const result = addTwoNumbers(4, 6);
// console.log("Result: ", result);
function loginUserMessage(username = "sandy") {
if(username === undefined){ // we can also use (!username) instead of ===
console.log("please enter a username");
return
}
return `${username} just logged in`
}
//console.log(loginUserMessage("sandeep")); //to print retrun value or print it
// console.log(loginUserMessage());
function calculateCartPrice(val1, val2, ...num1) { // (... is rest opertor) pass multipale value in functions
return num1
}
//console.log(calculateCartPrice(200, 400, 100, 900));
const user = {
username: "sandeep",
price: 199
}
// passing the object in function
function handleObject(anyobject){
// console.log(`username is ${anyobject.username} and price is ${anyobject.price}`);
}
//handleObject(user)
handleObject({
username: "sam",
price: 499
});
// passing the Array in function
const myNewArray = [200, 400, 700]
function returnSecondValue(getArray) {
return getArray[2]
}
// console.log(returnSecondValue(myNewArray));
console.log(returnSecondValue([200,400, 800, 500]));