When performing a property lookup like this._callback
, if the _callbacks
property does not exist for this
you will get undefined
. However if you just do a lookup on a bare name like b
, you will get a reference error if b
does not exist.
One option here is to use a ternary with the typeof
operator, which will return "undefined"
if the operand is a variable that has not been defined. For example:
var a = typeof b !== "undefined" ? b : (b = "Hello!");