-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionex.js
75 lines (52 loc) · 1.6 KB
/
functionex.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
// function saymyname(){
// console.log("This is first function");
// }
// saymyname()
// function add(x,y){
// console.log("Addtion is ",x+y);
// }
// add(3,4)
// function add(x,y){
// let result=x+y
// return result
// }
// const result=add(3,4)
// console.log("returned result is : ",result);
// function loginusermessage(username){
// return `${username} just logged in`
// }
// console.log(loginusermessage('aksay'))
//default parameters : at the calling time if we do not pass anything then default value will be taken as username
// function loginusermessage(username="userone"){
// return `${username} just logged in`
// }
// console.log(loginusermessage())//userone just logged in
// console.log(loginusermessage("Akshay"));//Akshay just logged in
//...rest operator is like var arg method in Java
// function calculateCartPrice(...num1){
// return num1
// }
// console.log(calculateCartPrice(500,200,300));//[ 500, 200, 300 ]
// function calculateCartPrice(val1,val2,...num1){
// return num1
// }
// console.log(calculateCartPrice(500,200,300,400));//[300,400] as 500 and 200 will kept into val1 and val2
//passing Object to the function
// const usernew={
// username:"Akshay",
// age:22
// }
function handleObject(anyObject){
console.log(`userName is ${anyObject.username} and The age is : ${anyObject.age}`);
}
//handleObject(usernew)
//another way directly passing object
handleObject({
username:"Anand",
age:23
})
//accepting and returing Array values in Javascript
function acceptarray(arr){
return arr[1]
}
console.log(acceptarray([1,2,3,4]))