What does “options = options || {}” mean in Javascript? [duplicate]
问题 This question already has an answer here: What does the construct x = x || y mean? 11 answers I came over a snippet of code the other day that I got curious about, but I\'m not really sure what it actually does; options = options || {}; My thought so far; sets variable options to value options if exists, if not, set to empty object. Yes/no? 回答1: This is useful to setting default values to function arguments, e.g.: function test (options) { options = options || {}; } If you call test without