Speed of comparing to null vs undefined in JavaScript

后端 未结 4 1952
生来不讨喜
生来不讨喜 2021-02-05 01:23

I have just run a very simple JavaScript performance test (don\'t ask why). The test declares a variable, but doesn\'t assign anything to it:

var x;

4条回答
  •  心在旅途
    2021-02-05 01:42

    if i think well, they are not the same. so you can't use null instead of undefined.

    typeof !== "undefined" vs. != null

提交回复
热议问题