English subtitles

← Dot and Bracket Notation - JavaScript Basics

Get Embed Code
5 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. Next up, we've got dot notation for
  2. objects, which we just used to access bio.name.
  3. Dot notation allows us to declare an object, and
  4. then define its properties outside the curly braces.
  5. >> The syntax looks like so, we'll have object.someproperty=somevalue.
  6. >> For instance, bio.email equals my email address.
  7. >> Hey, I see we didn't use var.
  8. >> Nope, with dot notation, there's no need to use var.
  9. We're adding properties to an object, not creating new variables.
  10. >> Right, and then we'll access them the same way we did before.
  11. >> Yep, we can use dot notation to access properties and
  12. append them to the page.
  13. >> There's at least one more syntax pattern to define the properties of
  14. an object right?
  15. >> Yeah, bracket notation.
  16. There's actually one more, but to learn more about that one,
  17. you can check out the instructor's notes.
  18. Bracket notation is similar to dot notation in that we can
  19. declare an object ,and then later in the code define its properties.
  20. This time, rather than dots, we'll use brackets.
  21. So, we have bio with the string, city, in brackets equals Mountain View, and
  22. bio, with the string email in brackets equals my email address.
  23. >> Right, so the syntax looks like object, then a string of
  24. the property name inside these square brackets equals some value.
  25. >> Yeah.
  26. So, if we wanted to append our city to the page,
  27. we just write this code right here.
  28. And when we refresh our page, we see that it still says mountain view