obj.length === +obj.length in javascript

It’s another way of writing if (typeof obj.length == 'number'). Why they do it that way, it’s anyone’s guess. Probably trying to be clever at the expense of readability. Which is not too uncommon these days, unfortunately…

Although it might be so that it can be compressed more by minifiers (YUI Compressor, Closure Compiler, UglifyJS, etc):

(a.length===+a.length) vs
(typeof a.length=='number')

Doing it their way would save 5 bytes, each instance.

Leave a Comment