-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.first_class_functions.js
More file actions
68 lines (28 loc) · 1.32 KB
/
9.first_class_functions.js
File metadata and controls
68 lines (28 loc) · 1.32 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
a(); // print : a called
b(); // TypeError : b is not a function
// Function Statement
// This is a function statement or function declaration
function a(){
console.log("a called");
}
// Function Expression
// Assigning function to a variable
var b=function(){
console.log("b is called");
}
// Main difference b/w the function statement and function expression is the Hoisting ie you can call the a() but b()m will give the error as the function is not initiallized to the variabe b
// Anonymous Functions -> Function without a name is an anonymous function [Anonymous Func's does not have their own identity]
// function(){}
// this will give the syntax error as per naming convention it should have a name
// Anonymous functions are used at the place where the functions are used as values
// Named function expression
var b=function xyz(){
console.log("b is called");
}
// but if you try to do xyz() it will give error that xyz is not defined
// Differenceb/w the parameters and the arguments
function fn(param1,param2){ // Here values passed to the functions are the parameters
}
fn(1,2); // you pass arguments to the function during calling
// FIRST CLASS FUNCTIONS
// The abilty of the functions to be passed as values or func returned from the functons are the first class functions