What is this in [removed] “var var1 = var1 || []”

后端 未结 8 2030
清歌不尽
清歌不尽 2021-02-15 11:43

I just want to increase my core javascript knowledge.

Sometimes I see this statement but I don\'t know what it does:

var var1 = var1 || [];
8条回答
  •  悲哀的现实
    2021-02-15 12:25

    It assigns an empty array to var1, if the boolean representation of it is false (for example it hasn't been initialized).

提交回复
热议问题