Is Subtracting Zero some sort of JavaScript performance trick?

前端 未结 7 1200
一向
一向 2020-12-06 00:32

Looking in the jQuery core I found the following code convention:

nth: function(elem, i, match){
    return match[3] - 0 === i;
},

And I wa

7条回答
  •  醉话见心
    2020-12-06 01:19

    Your main reason to use this syntax is if you have generic code that may be any number (int or float) and you want to do a type-sensitive compare (===)

提交回复
热议问题