Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:46:49+00:00 2026-05-28T00:46:49+00:00

I was looking at the source code for the Underscore.js library, specifically for the

  • 0

I was looking at the source code for the Underscore.js library, specifically for the map method (around line 85 on that page, and copied here):

  _.map = function(obj, iterator, context) {
    var results = [];
    if (obj == null) return results;
    if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
    each(obj, function(value, index, list) {
      results[results.length] = iterator.call(context, value, index, list);
    });
    if (obj.length === +obj.length) results.length = obj.length;
    return results;
  };

completely straightforward EXCEPT for the following line

    if (obj.length === +obj.length) results.length = obj.length;

Now, I read this to mean "if the object length is not a negative number…"
which, if my interpretation is right, implies that it might be!

So, dear experts, for what kinds of objects might

    obj.length === +obj.length 

be false? My understanding of === means it could return false if the type of obj.length didn’t match the type of +obj.length, but here my knowledge falls short. What kinds of things could + do to the kinds of things that obj.length might be? Is x === +x some sort of generic idiomatic test that I just don’t know? Is it response to some sort of special case that arises deeper in underscore.js, e.g., does underscore.js assign and track negative object.lengths for some conventional purpose? Guidance and advice will be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:46:50+00:00Added an answer on May 28, 2026 at 12:46 am

    I think that’s testing to see if typeof obj.length === 'number'

    As opposed to if it’s an object that has a length value of '2 days'

    So it knows if it’s an object like:

    var obj = { app: 'doctor', length: '45 min' };
    

    vs

    var obj = [ 0, 2, 1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking a source code of a particular page of my project and
I was looking at the source code of java.uti.concurrent.locks.AbstractQueuedSynchronizer and the acquire() method looks
Looking through the source code of a binary tree,I find the following function: //definition
I'm looking at the source code of a C++ project similar to one that
I'm looking through the source code for the CocoaHTTPServer project , more specifically the
I was looking at the source code to the hasattr built-in function and noticed
By looking at the source code for LinkedHashMaps from Sun, I see that there
I was looking at some source code, specifically for Paypal IPN, and I noticed
I'm looking through the source code of a project written in C. Here is
Looking on some source code I've inherited, there's a snippet of code that calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.