Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejavascript
doesnotexist.defaultsTo(x);  // returns the value of x
doesnotexist.defaultsTo([]); // returns the empty array
doesnotexist.defaultsTo([], "doesnotexist was null"); // returns the empty array and writes a message to log

The operator is most often used to guard against null values.

...