Can anyone show me an example? I seem to be missing something.
Let’s say you have an object called people
and it has a nameInput
property which contains the string “John”.
const people = {
age: 25,
nameInput: John
};
Now, say you wanted to store the value of nameInput
in a variable called nameData
. Now you COULD just do…
const nameData = people[0][1];
However, a much simpler and more readable method would be to use dot notation.
If we wanted to access nameInput
from the object people
. We could simply do this…
const nameData = people.nameInput;
If you found my reply confusing, just let me know and I’ll try my best to make it simpler!
Thank you for your response! Would you mind showing me an example in which the value “people” were a string with more than one word? For example “tall people”. Thanks!
Variables don’t allow the usage of 2 words separately. If you want to use two words, try using camelCase =)
Ex.
Instead of…
const "tall people" = "people"; // this would bring an error
We can do…
const tallPeople = "people"; // this would be correct
=)
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.