6/6 unexpected token [


#1

I've refreshed, copied and pasted, reset my code, and checked everything, I still get SyntaxError: unexpected token [ 5/6 passed fine and I only added everything under the add function, and removed the call for the search function. here is all my code:

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);
}

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

/*Create a search function
then call it passing "Jones"*/
var search = function (lastName) {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        if (lastName === contacts[i].lastName) {
            printPerson(contacts[i]);
        }
    }
};

var add = function (firstName, lastName, phoneNumber, email) {
    var contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
    }
};

add("Jane", "Doe", "(650) 999-9999", "jane.doe@example.com");
list();

#2

ok just figured out what it was, I removed 'var' in front of contacts, so is now:

var add = function (firstName, lastName, phoneNumber, email) {
    contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
    }
};

but I thought since we're creating a new array in the contacts array that it has to be declared, can anyone please explain this? Thank you in advance