Is multiplier a function or a variable that stores the return of function?

const multiplier = (item, multi) => item * multi;
multiplier(4, 2);

In the above code what is multiplier, is it a variable that stores the return of the arrow function or a function since it is being called multiplier(4, 2); .

It is a function (arrow function to be exact) declaration.

The second line calls the function. However, the call to the function is kind of pointless as the value returned is not assigned to anything.

It is like writing:

function multiplier (item, multi) {
  return item * multi;
}
multiplier(4, 2);
const multiplier = (item, multi) => item * multi;
multiplier(4, 2);

I was reading arrow functions when I came across this

const multiplier = function (item, multi) {
  return  item * multi;
};
multiplier(4, 2);

if this is the case.
Can you explain now ?

The latter is known as a function expression. It is similar but has some differences when compared to a declared function.

1 Like