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 6378775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:03:06+00:00 2026-05-25T02:03:06+00:00

This is valid and returns the string 10 in JavaScript ( more examples here

  • 0

This is valid and returns the string "10" in JavaScript (more examples here):

console.log(++[[]][+[]]+[+[]])

Why? What is happening here?

  • 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-25T02:03:06+00:00Added an answer on May 25, 2026 at 2:03 am

    If we split it up, the mess is equal to:

    ++[[]][+[]]
    +
    [+[]]
    

    In JavaScript, it is true that +[] === 0. + converts something into a number, and in this case it will come down to +"" or 0 (see specification details below).

    Therefore, we can simplify it (++ has precendence over +):

    ++[[]][0]
    +
    [0]
    

    Because [[]][0] means: get the first element from [[]], it is true that:

    [[]][0] returns the inner array ([]). Due to references it’s wrong to say [[]][0] === [], but let’s call the inner array A to avoid the wrong notation.

    ++ before its operand means “increment by one and return the incremented result”. So ++[[]][0] is equivalent to Number(A) + 1 (or +A + 1).

    Again, we can simplify the mess into something more legible. Let’s substitute [] back for A:

    (+[] + 1)
    +
    [0]
    

    Before +[] can coerce the array into the number 0, it needs to be coerced into a string first, which is "", again. Finally, 1 is added, which results in 1.

    • (+[] + 1) === (+"" + 1)
    • (+"" + 1) === (0 + 1)
    • (0 + 1) === 1

    Let’s simplify it even more:

    1
    +
    [0]
    

    Also, this is true in JavaScript: [0] == "0", because it’s joining an array with one element. Joining will concatenate the elements separated by ,. With one element, you can deduce that this logic will result in the first element itself.

    In this case, + sees two operands: a number and an array. It’s now trying to coerce the two into the same type. First, the array is coerced into the string "0", next, the number is coerced into a string ("1"). Number + String === String.

    "1" + "0" === "10" // Yay!
    

    Specification details for +[]:

    This is quite a maze, but to do +[], first it is being converted to a string because that’s what + says:

    11.4.6 Unary + Operator

    The unary + operator converts its operand to Number type.

    The production UnaryExpression : + UnaryExpression is evaluated as follows:

    1. Let expr be the result of evaluating UnaryExpression.

    2. Return ToNumber(GetValue(expr)).

    ToNumber() says:

    Object

    Apply the following steps:

    1. Let primValue be ToPrimitive(input argument, hint String).

    2. Return ToString(primValue).

    ToPrimitive() says:

    Object

    Return a default value for the Object. The default value of an object is retrieved by calling the [[DefaultValue]] internal method of the object, passing the optional hint PreferredType. The behaviour of the [[DefaultValue]] internal method is defined by this specification for all native ECMAScript objects in 8.12.8.

    [[DefaultValue]] says:

    8.12.8 [[DefaultValue]] (hint)

    When the [[DefaultValue]] internal method of O is called with hint String, the following steps are taken:

    1. Let toString be the result of calling the [[Get]] internal method of object O with argument “toString”.

    2. If IsCallable(toString) is true then,

    a. Let str be the result of calling the [[Call]] internal method of toString, with O as the this value and an empty argument list.

    b. If str is a primitive value, return str.

    The .toString of an array says:

    15.4.4.2 Array.prototype.toString ( )

    When the toString method is called, the following steps are taken:

    1. Let array be the result of calling ToObject on the this value.

    2. Let func be the result of calling the [[Get]] internal method of array with argument “join”.

    3. If IsCallable(func) is false, then let func be the standard built-in method Object.prototype.toString (15.2.4.2).

    4. Return the result of calling the [[Call]] internal method of func providing array as the this value and an empty arguments list.

    So +[] comes down to +"", because [].join() === "".

    Again, the + is defined as:

    11.4.6 Unary + Operator

    The unary + operator converts its operand to Number type.

    The production UnaryExpression : + UnaryExpression is evaluated as follows:

    1. Let expr be the result of evaluating UnaryExpression.

    2. Return ToNumber(GetValue(expr)).

    ToNumber is defined for "" as:

    The MV of StringNumericLiteral ::: [empty] is 0.

    So +"" === 0, and thus +[] === 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is valid JavaScript to write something like this: function example(x) { Here is
private void EnsureCurrentlyValid() { //I'm valid if IDataErrorInfo.this[] returns null for every property var
I want to execute a javascript that returns a string like 'GEORGE SMITH'. I
Is this valid and correct? RewriteRule ^myOldPage.html$ /index.php#info [R] I'm specifically interested about the
I'm getting XML like this: <Items> <Row attr1=val></Row> <Row attr1=val2></Row> </Items> This is valid
(I hope this is a valid question) As I stated in my title, I'm
Is this code possible? switch (rule) { case 'email' || 'valid_email': valid = this.validate_email(field);
Q1 FormsAuthentication.CookieDomain property specifies the domain for which this cookie is valid. Overriding this
Why can't enum's constructor access static fields and methods? This is perfectly valid with
Is this the correct (or even a valid way) to use emums in Objective-C?

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.