Why does . . . .0 evaluate to ?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












59














I just found ....0 in friend's code. Evaluating it in console returns (empty object).



Why is that? What is the meaning of 4 dots in JavaScript?










share|improve this question



















  • 10




    Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
    – Jeremy Harris
    Dec 25 '18 at 18:30










  • This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
    – Salman A
    Dec 26 '18 at 9:38






  • 1




    Always relevant
    – MikeTheLiar
    Dec 26 '18 at 14:36











  • @JeremyHarris the magic of HNQ
    – Pac0
    Dec 26 '18 at 21:31















59














I just found ....0 in friend's code. Evaluating it in console returns (empty object).



Why is that? What is the meaning of 4 dots in JavaScript?










share|improve this question



















  • 10




    Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
    – Jeremy Harris
    Dec 25 '18 at 18:30










  • This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
    – Salman A
    Dec 26 '18 at 9:38






  • 1




    Always relevant
    – MikeTheLiar
    Dec 26 '18 at 14:36











  • @JeremyHarris the magic of HNQ
    – Pac0
    Dec 26 '18 at 21:31













59












59








59


8





I just found ....0 in friend's code. Evaluating it in console returns (empty object).



Why is that? What is the meaning of 4 dots in JavaScript?










share|improve this question















I just found ....0 in friend's code. Evaluating it in console returns (empty object).



Why is that? What is the meaning of 4 dots in JavaScript?







javascript spread-syntax number-literal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 25 '18 at 15:57

























asked Dec 25 '18 at 11:37









Mist

41247




41247







  • 10




    Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
    – Jeremy Harris
    Dec 25 '18 at 18:30










  • This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
    – Salman A
    Dec 26 '18 at 9:38






  • 1




    Always relevant
    – MikeTheLiar
    Dec 26 '18 at 14:36











  • @JeremyHarris the magic of HNQ
    – Pac0
    Dec 26 '18 at 21:31












  • 10




    Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
    – Jeremy Harris
    Dec 25 '18 at 18:30










  • This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
    – Salman A
    Dec 26 '18 at 9:38






  • 1




    Always relevant
    – MikeTheLiar
    Dec 26 '18 at 14:36











  • @JeremyHarris the magic of HNQ
    – Pac0
    Dec 26 '18 at 21:31







10




10




Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
– Jeremy Harris
Dec 25 '18 at 18:30




Viewed almost 2500 times in 6 hours? It appears your friend is using the spread operator in a different context.
– Jeremy Harris
Dec 25 '18 at 18:30












This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
– Salman A
Dec 26 '18 at 9:38




This is more of a "how this expression is parsed" question. Type this in JS console and you'll notice that the 4th dot is colored differently... same color as zero.
– Salman A
Dec 26 '18 at 9:38




1




1




Always relevant
– MikeTheLiar
Dec 26 '18 at 14:36





Always relevant
– MikeTheLiar
Dec 26 '18 at 14:36













@JeremyHarris the magic of HNQ
– Pac0
Dec 26 '18 at 21:31




@JeremyHarris the magic of HNQ
– Pac0
Dec 26 '18 at 21:31












4 Answers
4






active

oldest

votes


















71














Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.



Spreading 0 (or any number) into an object yields an empty object, therefore .






share|improve this answer


















  • 9




    Spreading any number yields an empty object.
    – Kresimir
    Dec 25 '18 at 11:43






  • 8




    Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
    – Hitesh Kumar
    Dec 25 '18 at 16:37






  • 2




    @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
    – NikxDa
    Dec 25 '18 at 16:39







  • 2




    NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
    – Mist
    Dec 26 '18 at 0:29






  • 1




    @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
    – NikxDa
    Dec 26 '18 at 1:08


















49














Three dots in an object literal are a spread property, e.g.:



 const a = b: 1, c: 1 ;
const d = ...a, e: 1 ; // b: 1, c: 1, e: 1


The last dot with a 0 is a number literal .0 is the same as 0.0. Therefore this:



 ...(0.0) 


spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.






share|improve this answer






















  • You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
    – Mist
    Dec 25 '18 at 11:48






  • 3




    @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
    – Jonas Wilms
    Dec 25 '18 at 11:50










  • What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
    – Mist
    Dec 25 '18 at 11:56






  • 1




    Thanks! I see why my key on number couldn't work. Yayy boxing!
    – Mist
    Dec 25 '18 at 12:06






  • 3




    Numbers don't have any own enumerable properties. But they do have properties.
    – Patrick Roberts
    Dec 26 '18 at 3:39


















4














In a simple terms ... spread operator in javascript extends one object/array with another.



So, when babelifier tries extending one with another, it has to identify whether it is trying to extend an array or an object.



In the case of array, it iterates over elements.



In the case of object, it iterates over keys.



In this scenario, the babelyfier is trying to extract keys for number by checking the Object's own property call which is missing for number so it returns empty Object.






share|improve this answer


















  • 11




    new word! i.stack.imgur.com/VyYqA.png
    – uhoh
    Dec 27 '18 at 0:45



















0














Spread operator ... allows iterables to expand. It means that those data types that can be defined in form of key-value pairs can be expanded. In terms of Object we call key-value pair as Object property and it's value whereas in terms of arrays we can think index as key and element in array as it's value.



let obj = a: 4, b: 1;
let obj2 = ...obj, c: 2, d: 4; // a: 4, b: 1, c: 2, d: 4

let arr1 = ['1', '2'];
let obj3 = ...arr1, ...['3']; // 0: "3", 1: "2"


In terms of array, as it takes index as key so here it replaces element '1' of arr1 with '3' because both of them have same index in different array.



With strings too spread operator returns non-empty object. As string is an array of character so it treats string as an array.



let obj4 = ...'hi',...'hello' // 0: "h", 1: "e", 2: "l", 3: "l", 4: "o"
let obj5 = ...'y',...'x' // 0: "x"


But with other primitive data types it return empty object



with Numbers



let obj6 = ...0.0, ...55 // 


with Boolean



let obj7 = ...true, ...false // 


In conclusion those data types that can be treated in form of key-value pairs when used with spread operator ... returns non-empty object otherwise it returns empty object






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53922010%2fwhy-does-0-evaluate-to%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    71














    Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.



    Spreading 0 (or any number) into an object yields an empty object, therefore .






    share|improve this answer


















    • 9




      Spreading any number yields an empty object.
      – Kresimir
      Dec 25 '18 at 11:43






    • 8




      Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
      – Hitesh Kumar
      Dec 25 '18 at 16:37






    • 2




      @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
      – NikxDa
      Dec 25 '18 at 16:39







    • 2




      NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
      – Mist
      Dec 26 '18 at 0:29






    • 1




      @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
      – NikxDa
      Dec 26 '18 at 1:08















    71














    Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.



    Spreading 0 (or any number) into an object yields an empty object, therefore .






    share|improve this answer


















    • 9




      Spreading any number yields an empty object.
      – Kresimir
      Dec 25 '18 at 11:43






    • 8




      Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
      – Hitesh Kumar
      Dec 25 '18 at 16:37






    • 2




      @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
      – NikxDa
      Dec 25 '18 at 16:39







    • 2




      NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
      – Mist
      Dec 26 '18 at 0:29






    • 1




      @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
      – NikxDa
      Dec 26 '18 at 1:08













    71












    71








    71






    Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.



    Spreading 0 (or any number) into an object yields an empty object, therefore .






    share|improve this answer














    Four dots actually have no meaning. ... is the spread operator, and .0 is short for 0.0.



    Spreading 0 (or any number) into an object yields an empty object, therefore .







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 26 '18 at 1:07

























    answered Dec 25 '18 at 11:40









    NikxDa

    2,94111532




    2,94111532







    • 9




      Spreading any number yields an empty object.
      – Kresimir
      Dec 25 '18 at 11:43






    • 8




      Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
      – Hitesh Kumar
      Dec 25 '18 at 16:37






    • 2




      @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
      – NikxDa
      Dec 25 '18 at 16:39







    • 2




      NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
      – Mist
      Dec 26 '18 at 0:29






    • 1




      @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
      – NikxDa
      Dec 26 '18 at 1:08












    • 9




      Spreading any number yields an empty object.
      – Kresimir
      Dec 25 '18 at 11:43






    • 8




      Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
      – Hitesh Kumar
      Dec 25 '18 at 16:37






    • 2




      @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
      – NikxDa
      Dec 25 '18 at 16:39







    • 2




      NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
      – Mist
      Dec 26 '18 at 0:29






    • 1




      @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
      – NikxDa
      Dec 26 '18 at 1:08







    9




    9




    Spreading any number yields an empty object.
    – Kresimir
    Dec 25 '18 at 11:43




    Spreading any number yields an empty object.
    – Kresimir
    Dec 25 '18 at 11:43




    8




    8




    Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
    – Hitesh Kumar
    Dec 25 '18 at 16:37




    Spreading 0 (or any number) yields an empty object not necessarily if you spread a number at any other places apart from an object, it will throw an error eg [...0] throws an error.
    – Hitesh Kumar
    Dec 25 '18 at 16:37




    2




    2




    @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
    – NikxDa
    Dec 25 '18 at 16:39





    @HiteshKumar Spreading non-iterable objects inside an array will indeed throw an error, but that has nothing to do with this question. I am referring to the object-spread mentioned. :)
    – NikxDa
    Dec 25 '18 at 16:39





    2




    2




    NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
    – Mist
    Dec 26 '18 at 0:29




    NikxDa I think that @HiteshKumar made an important point. It's better to be more explicit about cases where your statements holds true. Spreading 0 (or any number) in object literal yields an empty object Contains more useful information..
    – Mist
    Dec 26 '18 at 0:29




    1




    1




    @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
    – NikxDa
    Dec 26 '18 at 1:08




    @Mist I've updated the answer. I don't think it's needed, but it might be good for clarification. Thanks for the update!
    – NikxDa
    Dec 26 '18 at 1:08













    49














    Three dots in an object literal are a spread property, e.g.:



     const a = b: 1, c: 1 ;
    const d = ...a, e: 1 ; // b: 1, c: 1, e: 1


    The last dot with a 0 is a number literal .0 is the same as 0.0. Therefore this:



     ...(0.0) 


    spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.






    share|improve this answer






















    • You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
      – Mist
      Dec 25 '18 at 11:48






    • 3




      @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
      – Jonas Wilms
      Dec 25 '18 at 11:50










    • What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
      – Mist
      Dec 25 '18 at 11:56






    • 1




      Thanks! I see why my key on number couldn't work. Yayy boxing!
      – Mist
      Dec 25 '18 at 12:06






    • 3




      Numbers don't have any own enumerable properties. But they do have properties.
      – Patrick Roberts
      Dec 26 '18 at 3:39















    49














    Three dots in an object literal are a spread property, e.g.:



     const a = b: 1, c: 1 ;
    const d = ...a, e: 1 ; // b: 1, c: 1, e: 1


    The last dot with a 0 is a number literal .0 is the same as 0.0. Therefore this:



     ...(0.0) 


    spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.






    share|improve this answer






















    • You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
      – Mist
      Dec 25 '18 at 11:48






    • 3




      @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
      – Jonas Wilms
      Dec 25 '18 at 11:50










    • What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
      – Mist
      Dec 25 '18 at 11:56






    • 1




      Thanks! I see why my key on number couldn't work. Yayy boxing!
      – Mist
      Dec 25 '18 at 12:06






    • 3




      Numbers don't have any own enumerable properties. But they do have properties.
      – Patrick Roberts
      Dec 26 '18 at 3:39













    49












    49








    49






    Three dots in an object literal are a spread property, e.g.:



     const a = b: 1, c: 1 ;
    const d = ...a, e: 1 ; // b: 1, c: 1, e: 1


    The last dot with a 0 is a number literal .0 is the same as 0.0. Therefore this:



     ...(0.0) 


    spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.






    share|improve this answer














    Three dots in an object literal are a spread property, e.g.:



     const a = b: 1, c: 1 ;
    const d = ...a, e: 1 ; // b: 1, c: 1, e: 1


    The last dot with a 0 is a number literal .0 is the same as 0.0. Therefore this:



     ...(0.0) 


    spreads all properties of the number object into the object, however as numbers don't have any (own) properties you get back an empty object.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 26 '18 at 19:59

























    answered Dec 25 '18 at 11:42









    Jonas Wilms

    55.8k42750




    55.8k42750











    • You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
      – Mist
      Dec 25 '18 at 11:48






    • 3




      @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
      – Jonas Wilms
      Dec 25 '18 at 11:50










    • What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
      – Mist
      Dec 25 '18 at 11:56






    • 1




      Thanks! I see why my key on number couldn't work. Yayy boxing!
      – Mist
      Dec 25 '18 at 12:06






    • 3




      Numbers don't have any own enumerable properties. But they do have properties.
      – Patrick Roberts
      Dec 26 '18 at 3:39
















    • You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
      – Mist
      Dec 25 '18 at 11:48






    • 3




      @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
      – Jonas Wilms
      Dec 25 '18 at 11:50










    • What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
      – Mist
      Dec 25 '18 at 11:56






    • 1




      Thanks! I see why my key on number couldn't work. Yayy boxing!
      – Mist
      Dec 25 '18 at 12:06






    • 3




      Numbers don't have any own enumerable properties. But they do have properties.
      – Patrick Roberts
      Dec 26 '18 at 3:39















    You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
    – Mist
    Dec 25 '18 at 11:48




    You lead me to thinking - I can spread any variable, and own keys will be spread into the new object? It works for Function (function x() ), (x.k = 'v'), (...x)// k: 'v' but doesn't work for Number (x = 10), (x.k = 'v'), (...x) //
    – Mist
    Dec 25 '18 at 11:48




    3




    3




    @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
    – Jonas Wilms
    Dec 25 '18 at 11:50




    @mist because numbers (and other primitives) get "boxed" into objects when you work with them as objects, and "unboxed" directly afterwards. Therefore x.k will get lost.
    – Jonas Wilms
    Dec 25 '18 at 11:50












    What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
    – Mist
    Dec 25 '18 at 11:56




    What does 'boxed' means exactly? E.g. when I used the dot operator (property) I worked with the number as object. If I am correct, that's just one case. Are there other cases when 'boxing' is happening? Does it apply only to numbers? Is there a perf reason or something? I guess this is for other question, and I should study it further. Could you point me to some book or something?
    – Mist
    Dec 25 '18 at 11:56




    1




    1




    Thanks! I see why my key on number couldn't work. Yayy boxing!
    – Mist
    Dec 25 '18 at 12:06




    Thanks! I see why my key on number couldn't work. Yayy boxing!
    – Mist
    Dec 25 '18 at 12:06




    3




    3




    Numbers don't have any own enumerable properties. But they do have properties.
    – Patrick Roberts
    Dec 26 '18 at 3:39




    Numbers don't have any own enumerable properties. But they do have properties.
    – Patrick Roberts
    Dec 26 '18 at 3:39











    4














    In a simple terms ... spread operator in javascript extends one object/array with another.



    So, when babelifier tries extending one with another, it has to identify whether it is trying to extend an array or an object.



    In the case of array, it iterates over elements.



    In the case of object, it iterates over keys.



    In this scenario, the babelyfier is trying to extract keys for number by checking the Object's own property call which is missing for number so it returns empty Object.






    share|improve this answer


















    • 11




      new word! i.stack.imgur.com/VyYqA.png
      – uhoh
      Dec 27 '18 at 0:45
















    4














    In a simple terms ... spread operator in javascript extends one object/array with another.



    So, when babelifier tries extending one with another, it has to identify whether it is trying to extend an array or an object.



    In the case of array, it iterates over elements.



    In the case of object, it iterates over keys.



    In this scenario, the babelyfier is trying to extract keys for number by checking the Object's own property call which is missing for number so it returns empty Object.






    share|improve this answer


















    • 11




      new word! i.stack.imgur.com/VyYqA.png
      – uhoh
      Dec 27 '18 at 0:45














    4












    4








    4






    In a simple terms ... spread operator in javascript extends one object/array with another.



    So, when babelifier tries extending one with another, it has to identify whether it is trying to extend an array or an object.



    In the case of array, it iterates over elements.



    In the case of object, it iterates over keys.



    In this scenario, the babelyfier is trying to extract keys for number by checking the Object's own property call which is missing for number so it returns empty Object.






    share|improve this answer














    In a simple terms ... spread operator in javascript extends one object/array with another.



    So, when babelifier tries extending one with another, it has to identify whether it is trying to extend an array or an object.



    In the case of array, it iterates over elements.



    In the case of object, it iterates over keys.



    In this scenario, the babelyfier is trying to extract keys for number by checking the Object's own property call which is missing for number so it returns empty Object.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 26 '18 at 18:02

























    answered Dec 26 '18 at 11:51









    Rajendra kumar Vankadari

    1,117911




    1,117911







    • 11




      new word! i.stack.imgur.com/VyYqA.png
      – uhoh
      Dec 27 '18 at 0:45













    • 11




      new word! i.stack.imgur.com/VyYqA.png
      – uhoh
      Dec 27 '18 at 0:45








    11




    11




    new word! i.stack.imgur.com/VyYqA.png
    – uhoh
    Dec 27 '18 at 0:45





    new word! i.stack.imgur.com/VyYqA.png
    – uhoh
    Dec 27 '18 at 0:45












    0














    Spread operator ... allows iterables to expand. It means that those data types that can be defined in form of key-value pairs can be expanded. In terms of Object we call key-value pair as Object property and it's value whereas in terms of arrays we can think index as key and element in array as it's value.



    let obj = a: 4, b: 1;
    let obj2 = ...obj, c: 2, d: 4; // a: 4, b: 1, c: 2, d: 4

    let arr1 = ['1', '2'];
    let obj3 = ...arr1, ...['3']; // 0: "3", 1: "2"


    In terms of array, as it takes index as key so here it replaces element '1' of arr1 with '3' because both of them have same index in different array.



    With strings too spread operator returns non-empty object. As string is an array of character so it treats string as an array.



    let obj4 = ...'hi',...'hello' // 0: "h", 1: "e", 2: "l", 3: "l", 4: "o"
    let obj5 = ...'y',...'x' // 0: "x"


    But with other primitive data types it return empty object



    with Numbers



    let obj6 = ...0.0, ...55 // 


    with Boolean



    let obj7 = ...true, ...false // 


    In conclusion those data types that can be treated in form of key-value pairs when used with spread operator ... returns non-empty object otherwise it returns empty object






    share|improve this answer

























      0














      Spread operator ... allows iterables to expand. It means that those data types that can be defined in form of key-value pairs can be expanded. In terms of Object we call key-value pair as Object property and it's value whereas in terms of arrays we can think index as key and element in array as it's value.



      let obj = a: 4, b: 1;
      let obj2 = ...obj, c: 2, d: 4; // a: 4, b: 1, c: 2, d: 4

      let arr1 = ['1', '2'];
      let obj3 = ...arr1, ...['3']; // 0: "3", 1: "2"


      In terms of array, as it takes index as key so here it replaces element '1' of arr1 with '3' because both of them have same index in different array.



      With strings too spread operator returns non-empty object. As string is an array of character so it treats string as an array.



      let obj4 = ...'hi',...'hello' // 0: "h", 1: "e", 2: "l", 3: "l", 4: "o"
      let obj5 = ...'y',...'x' // 0: "x"


      But with other primitive data types it return empty object



      with Numbers



      let obj6 = ...0.0, ...55 // 


      with Boolean



      let obj7 = ...true, ...false // 


      In conclusion those data types that can be treated in form of key-value pairs when used with spread operator ... returns non-empty object otherwise it returns empty object






      share|improve this answer























        0












        0








        0






        Spread operator ... allows iterables to expand. It means that those data types that can be defined in form of key-value pairs can be expanded. In terms of Object we call key-value pair as Object property and it's value whereas in terms of arrays we can think index as key and element in array as it's value.



        let obj = a: 4, b: 1;
        let obj2 = ...obj, c: 2, d: 4; // a: 4, b: 1, c: 2, d: 4

        let arr1 = ['1', '2'];
        let obj3 = ...arr1, ...['3']; // 0: "3", 1: "2"


        In terms of array, as it takes index as key so here it replaces element '1' of arr1 with '3' because both of them have same index in different array.



        With strings too spread operator returns non-empty object. As string is an array of character so it treats string as an array.



        let obj4 = ...'hi',...'hello' // 0: "h", 1: "e", 2: "l", 3: "l", 4: "o"
        let obj5 = ...'y',...'x' // 0: "x"


        But with other primitive data types it return empty object



        with Numbers



        let obj6 = ...0.0, ...55 // 


        with Boolean



        let obj7 = ...true, ...false // 


        In conclusion those data types that can be treated in form of key-value pairs when used with spread operator ... returns non-empty object otherwise it returns empty object






        share|improve this answer












        Spread operator ... allows iterables to expand. It means that those data types that can be defined in form of key-value pairs can be expanded. In terms of Object we call key-value pair as Object property and it's value whereas in terms of arrays we can think index as key and element in array as it's value.



        let obj = a: 4, b: 1;
        let obj2 = ...obj, c: 2, d: 4; // a: 4, b: 1, c: 2, d: 4

        let arr1 = ['1', '2'];
        let obj3 = ...arr1, ...['3']; // 0: "3", 1: "2"


        In terms of array, as it takes index as key so here it replaces element '1' of arr1 with '3' because both of them have same index in different array.



        With strings too spread operator returns non-empty object. As string is an array of character so it treats string as an array.



        let obj4 = ...'hi',...'hello' // 0: "h", 1: "e", 2: "l", 3: "l", 4: "o"
        let obj5 = ...'y',...'x' // 0: "x"


        But with other primitive data types it return empty object



        with Numbers



        let obj6 = ...0.0, ...55 // 


        with Boolean



        let obj7 = ...true, ...false // 


        In conclusion those data types that can be treated in form of key-value pairs when used with spread operator ... returns non-empty object otherwise it returns empty object







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        SR Thapa

        1208




        1208



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53922010%2fwhy-does-0-evaluate-to%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay