-4

No issues, i was just wondering, when going through the source code. Here, Why === faster than == in JavaScript? it says === is actually faster, so why use == in this case?

_.each = _.forEach = function(obj, iteratee, context) {
    if (obj == null) return obj;
Community
  • 1
  • 1
manimis
  • 18
  • 1
  • 4

2 Answers2

0

Most likely because x == null is true for (only) x = null and x = undefined. I.e. you capture both cases with a single comparison.

That's one of the few exceptions where loose comparison is useful.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

You will get your answer here

The "==" operator compare for equality after doing necessary conversion as "===" will not do any conversion. for this reason "===" operator is faster than "==" operator. But in your code, there is validation if obj is null or undefined. for ex.

var obj=null

obj==undefined //true
obj==null      //true

obj===undefined //false   **This is the difference
obj===null      //true
Community
  • 1
  • 1
Laxmikant Dange
  • 7,606
  • 6
  • 40
  • 65