Javascript Functions Types

Vin Andros
2 min readMar 24, 2021
Photo by Markus Spiske on Unsplash

Functions as Values

This is the most commonly used way, we create a binding to assign a function as a value. In these cases, we can use this function like any other binding, allowing us to pass the function to other functions and so on, also we can assign a new value, went if not constant.

const square = function(x) {
return x*x;
}
console.log(square(12))
// --> 144

Functions with declaration Notation

This is a short way to create a function binding, we use the function keyword at the start of a statement. The main key difference is when you call these functions because they are conceptually moved to the top of the scope, in consequence, we can call the function before it’s have been defined.

console.log("The future says:", future());function future(){
return "You'll never have flying cars";
}

Arrow Functions

This last way looks very different from the others. In this case, instead of the function keyword, it uses an arrow (=>) made up of an equal sign and a greater-than character, for example:

const square = (X) => { return x*x };
//also you can do this
const square = X => X * X; // implicit return, we remove () because we have just one paremeter.

If you like to get deep, check this out Eloquent Javascript functions.

--

--

Vin Andros

Passionate reading || Coding Addicted || FullStack Web Developer from Costa Rica