Js interview questions [0] = [0] [0] = 0 {} = = 0, what are the results of these three and why?

Baidu can"t find it directly, maybe it has something to do with its search mechanism, so come here to ask which god to answer, thank you very much

Mar.10,2021

Let me answer separately:

  • [0] = = [0] is false because the addresses of the two arrays are different
  • [0] = = 0 is true , [0] will first change to the original value, that is,'0' = = 0
  • {} = = 0 will report an error, because if you write this directly on the browser console, {} is treated by as an empty code block , not an object, and the last execution is actually = = 0 . If you write ({} = = 0) , it is false .

check the js equality operation rules

equality operator, to put it simply:

  1. Type conversion occurs when the type is different;
  2. addresses are compared when they are of the same type and when objects (including arrays, etc.) are reference types.
Menu