-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions-With-Objects.js
More file actions
46 lines (35 loc) · 1.31 KB
/
Functions-With-Objects.js
File metadata and controls
46 lines (35 loc) · 1.31 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
const sum_of_numbers=function(num1){ // this will only take the first parameter and avoid rest
return num1
}
const result=sum_of_numbers(100,200,300)
console.log("result is :- ",result)
// for avoiding problem we faced above we do :-
const sum_of_number=function(...num1){ // doing this will take all the parameters passed during function call
return num1
}
const answer=sum_of_number(100,200,300)
console.log("result is :- ",answer) //all numbers passed in an array
//----------------------------------------------------------------------------------------------------------------
// another way of defining a function
function function_name(){
return "function executed!!"
}
const res=function_name()
console.log("result of another method of defining a function :- ",res)
//---------------------------------------------------------------------------------------------------------------
//accessing an Object data inside function()
const my_obj={
name:"anisha",
email:"xyz123@gmail.com",
location:"delhi",
course:"JS-tutorial"
}
function access_myObj(obj){
return `my_obj data found :-
name - ${obj.name} ,
email - ${obj.email} ,
location - ${obj.location} ,
course - ${obj.course}`;
}
const output=access_myObj(my_obj)
console.log(output)