-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_function.js
More file actions
84 lines (56 loc) · 1.45 KB
/
06_function.js
File metadata and controls
84 lines (56 loc) · 1.45 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
//functions in js
/**
* Function is a block of code which we can reuse any where in he program to call set of code or instruction
* ex :-
* function addTwoNumbers(num1,num2){
* console.log(num+num2)
* }
*/
function sayMyName() {
console.log("Vikas chenna");
}
// sayMyName();
function addTwoNumbers(num1, num2) {
console.log(num1 + num2);
}
// addTwoNumbers(5,4);
let myfun = function addThreeNum(num1,num2,num3){
console.log(num1+num2+num3);
}
// console.log(myfun(5,5,5));
function sumTwo(num1,num2){
return num1 + num2
}
let printSumTwo = sumTwo(5,6);
// console.log(printSumTwo);
///we can pass objects in functions
let user = {
name : "vikas",
age : 25,
email : "vikas@gmail.com"
}
function printName(anyObject){
console.log(`hello ${anyObject.name} your email is ${anyObject.email} is registered`);
}
printName(user)
// or
printName({
name:"vikas chenna",
age:25
})
let myArray = [1,2,4,5,6]
function printArray(anyArray){
console.log(anyArray[2]);
}
// printArray(myArray)
// or
printArray([1,2,"Vikas chenna",4,5])
//we can pass more than 1 parameters and also can be print using ( rest operator (...) )
function addToCart(...numbers){
console.log(numbers);
}
addToCart(10,20,30,40,50,30,4,5,80,90,100)
function addToCart1(val1,val2,...numbers){
console.log(numbers);
}
addToCart1(10,20,30,40,50,30,4,5,80,90,100) //10 and 20 assiign in val1 and val2 rest of numbers assign in ...numbers