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 -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -