InterviewSolution
Saved Bookmarks
| 1. |
What are anonymous functions? Provide their syntax in TypeScript. |
|
Answer» An anonymous function is a function without a name. Anonymous FUNCTIONS are typically used as callback functions, i.e., they are passed around to other functions, only to be invoked by the other function at a later point in time. For example, setTimeout(function () { console.log('Run after 2 seconds')}, 2000);You can invoke an anonymous function as soon as it’s created. It’s called ‘immediately invoked function execution (IIFE)’, For example:(function() { console.log('Invoked immediately after CREATION');})(); |
|