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

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -