Function statements
// Allows hoisting
function test(){
console.log("function statements");
};
test();
Function expressions
// Doesnot allow hoisting
var a = function (){
console.log(function expression);
};
a();
Named function expressions
var a = function test(){
console.log("named function expressions");
};
a();
Function declaration
function test() {
console.log("function declaration");
};
test();
Anonymous function
var x = (){
};
x();
First class function
// Ability to pass as argument and return functions as value
var x = function test(abc){
console.log(abc);
return function a(){
};
};
x(function () {};);
Arrow functions
var x = () => console.log("Arrow functions");
Generator functions
function* square(a){
for(let x=a;; x*=a){
yield x;
}
};
for(let z of square(2)){
console.log(z);
}
new Function
// Allows to convert string to function useful to handle server return codes.
var a = new Function ('a','b', 'return a+b');
console.log( sum(3,6));
Top comments (0)