4. Listing Everybody



Hello I got “TypeError: Cannot read property ‘firstName’ of undefined” but I believe it should be ok. Can you please look at it and check where I made mistake?

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 ( i = 0; i < contactsLength; i++); {


you have an unnecessary semi-colon after i++) which interrupts the loop, causing problems.


OMG, thanks man :slight_smile:

Any advices how to avoid such mistakes? :slight_smile:


you’re welcome :slight_smile:

I wish i knew, i once made this terrible mistake:

do {
    // don't remember what loop did
} while (someVariable = 1)

and i couldn’t figure it out what the mistake was, why i had an infinity loop

as you code more, your debug skills will get better, and you will make mistake less easily, so i think the only advise here is to keep coding/programming to get better

if you can’t see what the mistake in my code was, i used a single equal sign (which means assign) rather then two or three equal signs, which means check if equal, took me 30-60 minutes to find it :frowning:


Pity to hear that there is no other way to avoid such mistakes then to be more skilled in writing the code :slight_smile:

And this mistake in your code may took me far more then 30-60min to find this out :slight_smile:

Hard life coders have it seems :smiley:


yep, programmers life is very difficult, if you have some time to spare:


some of these bugs are insane :frowning:


This type of bug mentioned by the Dave Baggett should be considered as pretty one :slight_smile:


good luck finding such a bug, as you can read, that takes weeks :open_mouth:


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