-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstClassFunctions&anonymousFunctions.js
More file actions
62 lines (40 loc) · 1.63 KB
/
FirstClassFunctions&anonymousFunctions.js
File metadata and controls
62 lines (40 loc) · 1.63 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
//function statement and function declaration as well
function xyz(){
console.log("hii");
}
//function expression
// assigning function as a value to the variable
var a=function (){
console.log("hii");
}
//anonymous function
//a function which does not contain any name
// function (){ //identifier exepcted
// }
//but we can use anonymous functions in function expression
//Named function Expression
// nothing usually we use anonymous function in function expressions but if we define name to it then it considered as named function expression
var b=function xyz(){
console.log("hello");
console.log(xyz); //here it does not throw any error as it is already had an entry in local scope of xyz
}
console.log(b);
console.log(xyz); //as xyz has no entry in the global execution context it throws reference error as it is not defined
//difference between [arameters and arguments
// the function where we define and give names in the paranthesis are called as parameters (idetifiers,labels)
// but from where we call that particular a\function and passing values to the parameters which we have defined while function declaration is knowmn as arguments(values)
function c( name, age){//these are parametrs
console.log(name,age);
}
c("swathi","27");//these are arguments
// First class functions
//first class citizens
// it's ability to treated as a vlue and passed as argument and return from function
function y(x){
console.log(x);
return x;//it can aslo return a function
}
y(function (){//it logs the anonymous function which we have passed
})
y(function z(){//ity logs the named function which we have passed
})