return String vs Integer vs undefined vs null

后端 未结 6 1753
醉话见心
醉话见心 2021-02-15 10:50

Why does javascript prefers to return a String over any other choices ?

Consider the following snippet.

var arr = [\'Hello1\', \'Hello2\', \         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-15 11:12

    Because it is evaluating in order from left to right.

    If you were to modify to this:

    return this[x] || null || 12 || 'aïe' || undefined ;
    

    Your answer would be 12.

提交回复
热议问题