-
Notifications
You must be signed in to change notification settings - Fork 0
/
9. functions.js
54 lines (39 loc) · 1002 Bytes
/
9. functions.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
// Function declaration (support hoisting)
function happy(){
console.log("happy birthday to you")
}
// Function Expression
happy = function(){
console.log("happy birthday")
}
// Arrow Function
happy = () => console.log("happy!")
// Default Parameters
function add(a=0, b=0){}
// Rest Parameters as array
function add(a, b, ...rest){}
// parameter destructuring
function print({name}){
console.log(name)
}
person = {
name: "Asad",
age: "12"
}
print(person)
// ----------------
// higher order function (function returning function)
function ok(){
return ()=>console.log("higher function")
}
fun = ok()
fun();
// ----------------
// function are objects as well that have many properties
// name property will give the name of function
happy.name
// we can also add our own properties to functions
happy.myOwnProperty = "very unique value"
happy.myOwnProperty
// functions also provide prototype property so we can add our properties
happy.prototype