notation

What does “options = options || {}” mean in Javascript? [duplicate]

核能气质少年 提交于 2019-11-25 23:17:02
问题 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

What is the difference between Θ(n) and O(n)?

不打扰是莪最后的温柔 提交于 2019-11-25 22:36:11
问题 Sometimes I see Θ(n) with the strange Θ symbol with something in the middle of it, and sometimes just O(n). Is it just laziness of typing because nobody knows how to type this symbol, or does it mean something different? 回答1: Short explanation: If an algorithm is of Θ(g(n)), it means that the running time of the algorithm as n (input size) gets larger is proportional to g(n). If an algorithm is of O(g(n)), it means that the running time of the algorithm as n gets larger is at most