Named function (Function declaration)
function helloWorld() {
console.log('Hello World');
}
helloWorld();
Named functions are used when the codes need to be executed several times.
Anonymous function
let helloWorld = function () {
console.log('Hello World');
}
console.log(helloWorld);
Anonymous functions are used the codes needs to be executed only once or twice and also used in event handler as below:
.onclick = function() {
console.log('Hello World')
}
Arrow function
const helloWorld = () => 'Hello World';
console.log(helloWorld);
Arrow functions are shorter ways of function expressions from ES6 and useful to write functions in short ways.
Top comments (0)