Speed of comparing to null vs undefined in JavaScript

后端 未结 4 2015
生来不讨喜
生来不讨喜 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:41

    I recently discovered that this:

     if (typeof this._minLat === 'undefined') {
       this._minLat = Math.min(...this.points.map(point => point.lat));
     }
     return this._minLat;
    

    seems to be many times faster than this:

     return  this._minLat || Math.min(...this.points.map(point => point.lat));    
    

提交回复
热议问题