9. Nouns and Verbs Go Together Syntax Question


How did the code know what .phone is when it called the function? .phone is not written anywhere in our code, Is phonebookEntry.phone just a function name and if so, why doesn't it have 'var' in front of it?

var phonebookEntry = {};

phonebookEntry.name = 'Oxnard Montalvo';
phonebookEntry.number = '(555) 555-5555';

phonebookEntry.phone = function() {    <---confused about the .phone here
  console.log('Calling ' + this.name + ' at ' + this.number + '...');



Satisfies the invocation.


It doesn't have a var with it because it is already declared and defined..We only do the declaration once. After that we can change the value and type of a variable on the fly.


Hi @mtf,

when you say that the variable is already declared and defined, you mean at the beginning of the code here?

var phonebookEntry = {};

So, if I want to make a function where the information is located inside objects, I have to add a new piece of information and to do that, I would put a '.' and then another word (the '.phone' part in this example) right?

phonebookEntry.phone = function() {


Yes. That is the objective.


ok thanks! I looked at the code some more and I was just confused about how the function was created by now I think I got it :smile: