variable === undefined vs. typeof variable === “undefined”

后端 未结 8 1363
情深已故
情深已故 2020-11-22 14:43

The jQuery Core Style Guidelines suggest two different ways to check whether a variable is defined.

  • Global Variables: typeof variable === "undefined&
8条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 15:21

    Because undefined is not always declared, but jQuery declares undefined in its main function. So they use the safe undefined value internally, but outside, they use the typeof style to be safe.

提交回复
热议问题