Here's something a Java or C# programmer would find maddening.  Since JavaScript is a dynamic language, the structure of your objects can change over the course of your program's execution.  Yep.  You have the ability through prototype inheritance to change anything on any object on the fly.

The downside is we have to write a bunch of code like this:

Basically, we're checking to see if our object foo which is composed with another object bar has some property named "baz".  If it does then it does something with it by passing it to a function.  If it doesn't, the whole function call is skipped.

JavaScript has a newish syntax that let's you check deeply nested chains of objects called the optional chaining operator.  It looks like this:

The syntax can be seen on lines 8 and 12.  The added question mark is effectively asking "does this object have this property or method on it?"  If it does, then it executes.  If it doesn't, it returns undefined.

This shortens the amount of code you have to write when dealing with objects that are chained together, and there's potentially no guarantee as the to the structure of an object.


Do you create web sites? Are you still running them on hosting providers instead of your own web server? Then you need this course! Learn to set up a full static web server for $5 per month with root access and you can install any additional software you'd like.

Learn these skills now in about two hours for just $29 USD