2

I understand what the code below does:

var x = myFunction(3, 4)

function myFunction (a, b) {
    return a * b;
}

console.log(x);

It will create a function called myFunction, call it with 3 and 4 and return 12.

But I don't understand what the difference between the above code and the code below.

var myFunction = function (a, b) {
    return a * b;
};

var x = myFunction(3, 4)
console.log(x);

If we can write code like the first one, why do we need to write code like the second one?

Thanks.

0 Answers0