Created
August 13, 2022 18:30
-
-
Save cds/394e920f31a832b7f5c5cf438cd31594 to your computer and use it in GitHub Desktop.
Anonymous Functions And Immediately Invocation Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 function without name anonymous | |
(function () { | |
}); | |
//2 function that with Immediately invocation | |
(function () { | |
console.log("Immediately invocation function") | |
})(); | |
//3 anonymous function with variable | |
let anonymous = function () { | |
console.log('Anonymous function stored in variable') | |
}; | |
anonymous(); | |
//4 anonymous function as argument to timeout function | |
setTimeout(function () { | |
console.log('Anonymous function as argument - Run after two second ') | |
}, 2000); | |
//5 function that with Immediately Invocation with arguments | |
let person = { | |
name: 'ChandrakantSangale', | |
city: 'Pune' | |
}; | |
(function () { | |
console.log(person.name + ' ' + person.city); | |
})(person); | |
//6 Arrow function with anonymous function | |
let simpleShow = function () { | |
console.log("simple function") | |
}; | |
//7 Arrow function with anonymous function | |
let simpleShowArrow = () => console.log('anonymous function with arrow') | |
//8 Arrow function with anonymous function | |
let add = function (a, b) { | |
return a + b; | |
} | |
//9 Arrow function with anonymous function | |
let addArrow = (a, b) => a + b; | |
//Q-Why anonymous function is used and advantages | |
// prevents the global namespaces from becoming littered(messy) with variables and functions that may not be needed further. It can be also be used to enable access to only the variables and functions. | |
//Q-What are self invoking function | |
// Self-Invoking Functions | |
// A self-invoking (also called self-executing) function is a nameless (anonymous) function that is invoked immediately after its definition. | |
// An anonymous function is enclosed inside a set of parentheses followed by another set of parentheses (), which does the execution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment