Alternative ways to code printPerson function


#1

I did the printPerson function the first way listed below, but then investigated the forum and found some people did it the second way, assigning the function to a variable.

What's the difference between the two methods? Why would you choose one over the other?

FIRST WAY:

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);

SECOND WAY -- ASSIGNING FUNCTION TO A VARIABLE

var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName);
}


#2

the only difference is the first one declares printPerson as a function right away, the second version declares a variable (var) called printPerson that ends up being a function. The compiler will determine what the var is at runtime as opposed to knowing its a function before runtime.

In this case its a matter of personal preference.