A common idiom with in programming is conditional assignment, usually to
set an undefined variable. Ruby has a nice operator, ||= for this purpose,
JavaScript doesn’t have such an operator. So often variables that are used
across multiple files, like namespaces, have to be repeatedly conditionally
assigned. By not doing so you may try to use the variable before it’s been
declared and have a ReferenceError thrown.
There are lots of ways to conditionally assign in JavaScript. This is the way I learned from Jeremy Ashkenas, and the way I like to do it:
|
This can also be used for arguments and local variables,
|