Person parameter


The code is correct, but I don’t understand what exactly the "person" parameter does. Is it some kind of universal parameter?
Why can’t I use "this.firstName" instead of "person.firstName"?

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: ""

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: ""

var contacts = [bob, mary];

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



I don’t understand how the person parameter knows it is connected to mary and bob.


printPerson is just a function, this is for objects/classes.

You already used parameters and arguments many times before? You can always check earlier lessons/documentation if you need a reminder

Short version, a function parameter (person in this case) serves as a placeholder, until you supply an argument when calling the function:

# function declaration with person parameter
function printPerson(person) {

# function call, supplying bob and mary as arguments

the arguments now get copied into the function parameter


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