Anonymous Function
Callback as an Arrow Function
If you prefer, you can also write the same callback function as an ES6 arrow function, which is a newer type of function in JavaScript:
setTimeout(() => {
console.log("This message is shown after 3 seconds");
}, 3000);
Anonymous Function
An anonymous function is a function without a name. An anonymous function is often not accessible after its initial creation. Here is an example of an anonymous function expression (the name is not used):
var myFunction = function() { statements }
It is also possible to provide a name inside the definition in order to create a named function expression:
var myFunction = function namedFunction(){ statements }
Last updated
Was this helpful?