Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 2
    Would you mind explaining how that works? Mainly, what does the '+' do? Commented Mar 3, 2014 at 14:21
  • 1
    This is good, but it is also true when the object is a function or a string as well as any other object with property length of type number. Why? Well, the unary + operator actually casts a variable as a number. So basically they are checking if obj.length is a number. [object Object] has no property length it is undefined so when you cast undefined as a number it becomes NaN the above check comes out as false. So it returns true if the object property length is a number, which in the case of arrays, strings, and functions it would be true. Underscore has to be doing more than just this. Commented Apr 12, 2014 at 0:36
  • This isn't good because you might create your own object that has a length prop, e.g. const myNovel = { length: 150 } It'll create false positives. Commented May 29, 2024 at 12:45