javascript - Empty object minus/plus empty object, and reverse value -


i have question. in console i'm training "arithmetics", like:

false + true // 1  

so, question is, why:

[] - {} // nan 

and

{} - [] // -0 

can explain this, because both of them types object. , know javascript have , falsy values. so, if take

boolean({}) // true boolean([]) // true 

in both have true , think result like:

true + true // 2 

or

true - true // 0 

in context (in console), {} empty block nothing, result same

- [] 

and [] coerce 0, seen by:

+[] 

if want {} treated empty object, try this:

({}) - [] 

you nan now, since empty object not coerce number.

update: work should expect in console (returning nan):

({} - []) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -