javascript - Difference between two statements that declare an object -
what difference between statement
var x = x || {};
and this. same thing? there performance difference?
var x = typeof x === "undefined" ? {} : x;
they're not same.
the ||
return object when x
any possible falsy value.
typeof
check only return {}
if x
undefined
.
according this test, undefined
check twice fast. that's because no type casting required.
Comments
Post a Comment