4. What's Up with this function syntax?


#1



I'm not having any issues really but I don't understand why I am being started with a different syntax for declaring the printPerson function. Throughout the entire course, this syntax has never been used... Why now? And no explanation. Very confusing. Can someone help me understand why I would use one over the other?

function printPerson(person) {...}

instead of

var printPerson = function(person) {...}


var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

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


#2

mdn - functions

A function definition (also called a function declaration, or function statement) is what you are using here:

function printPerson(person)

have you so far only been using Function expressions? example of function expression:

printPerson = function(person)

you should be fine to use that in this exercise as well, that shouldn't be a problem. You can read the documentation i provided about the differences between this two function creations


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.