My code works but im not sure why


Contact List Number 7 Search For a Friend.

So the problem is that I was able to get my code to work but im not 100% sure why it works. so be more specific im not sure why the "argument" parameter in the "search" function has to be in the square brackets [ ] and not in parentheses (). Can someone offer up an explanation I dont want to go forward and end up lost because i dont undersand the basics back here.

        if(friends[argument].firstName === name)


why would you use parentheses? parentheses are for function calls. Lets simplify the code a bit:

steve ={
   address:["3","Riverview Road","Sterling","MA","01564"]

now if we want to access a property of steve we have two choices:


if you want to read more about this you can do this here

i am going to borrow some explanation from this source:

You access the properties of an object with a simple dot-notation:


which is what we did here:


steve being the object, and firstName being the property.

Properties of JavaScript objects can also be accessed or set using a bracket notation:


this are the two ways you can access properties of an object, not with parentheses.

if we use a loop, we have to use the bracket notation. Since the for loop uses a string.


Thank you that makes more sense now.


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