TIL 16: javascript 5


Start at the beginning, or see previous post.

JavaScript Objects:

  • useful for storing data in a structured way
  • can represent real world objects
  • objects are similar to arrays, but instead of indexes, data in objects is accessed via properties

Accessing object properties:

  • there are two ways to access the properties of an object: bracket notation, or the dot operator
  • the dot operator is used when you know the name of the property you’re trying to access e.g. myObj.prop1
  • bracket notation can also be used – and must be, if the property name has a space in it e.g. myObj[“Space Name”] (note the quote marks, also)
  • bracket notation also allows accessing a property using a variable – this is useful for iterating through the properties, for example


Updating object properties:

  • after the object has been created, the properties can be updated at any time like any other variable. Either the dot or bracket notation can be used. E.g. myObj.prop1 = “new”;

Add new properties:

  • adding new properties works in the same way as modifying existing ones e.g. myObj.newProp = “more new”;
  • again, either dot or bracket notation can be used

Deleting properties:

  • use the delete keyword e.g. delete myObj.newProp;



3 responses »

    • I’m enjoying it! I’m not exactly a beginner programmer so I can’t wholly comment on how easy/difficult it is, but it’s a good refresher for a newish (to me) language, in lovely bite-sized chunks I can fit around everything else.

      Thanks for stopping by!

      Liked by 1 person

  1. Pingback: TIL 19: javascript 6 | diary of a scanner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s