I often see JavaScript code where a function may take in an "options" object and use it like:
var name = typeof options.name !== 'undefined' ? options.name : "Bob";
This seems like it would be equivalent to the following:
var name = options.name || "Bob";
Now, I understand that in certain situations you may actually care that options.name
is undefined
vs null
and this makes sense to me, but I often see this in situations where this distinction is not necessary.
I believe I have heard that people write code like this because of some bug in IE. Can someone elaborate please?