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

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -