Three types of functions in JavaScript!
Ali Bahaari
Posted on December 10, 2021
There are 3 ways which functions can be declared in JavaScript.
In this article, I'm going to show you and compare these.
Named Functions
This type receives a name for the function declaration:
function myFunction(text) {
console.log(text);
}
myFunction('Hello World!');
Anonymous Functions
This type doesn't receive explicitly any name for declaration. Instead, the function will be assigned to a variable for invoking.
const myFunction = function(text) {
console.log(text);
}
myFunction('Hello World!');
Arrow Functions
This type is similar to lambda functions in other programming languages. It doesn't receive explicitly any name (it will be assigned to a variable for invoking) and the structure is so simpler.
const myFunction = (text) => {
console.log(text);
}
myFunction('Hello World!');
BOOM! Now you've been learning 3 types of function declaration in JavaScript which may help you a lot in developing web applications and etc.
You can or may want to connect with me through the networks I've put on my website: Ali Bahaari's Website
Posted on December 10, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.