• 1 Post
  • 1.57K Comments
Joined 8 months ago
cake
Cake day: November 14th, 2023

help-circle


















  • Victor@lemmy.worldtoProgrammer Humor@programming.devJavaScript
    link
    fedilink
    arrow-up
    36
    arrow-down
    1
    ·
    edit-2
    4 days ago

    In node, I get the same result in both cases. "[object Object]"

    It’s calling the toString() method on both of them, which in the array case is the same as calling .join(",") on the array. For an empty array, that results in an empty string added to "[object Object]" at either end in the respective case in the picture.

    Not sure how we’d get 0 though. Anybody know an implementation that does that? Browsers do that maybe? Which way is spec compliant? Number([]) is 0, and I think maybe it’s in the spec that the algorithm for type coercion includes an initial attempt to convert to Number before falling back to toString()? I dunno, this is all off the top of my head.