Skip to content
DevMeme
3812 of 7590
Languages Post #4154 · source on Telegram

The Deceptive Simplicity of JavaScript's Number Type

Description

A two-panel 'Average Fan vs. Average Enjoyer' (GigaChad) meme comparing numeric data types in different programming languages. On the left, a frustrated, angry-looking young man represents 'JAVA, C, C++, ETC'. The text above him reads 'float, double, int aarrghhhhh', symbolizing the annoyance of dealing with multiple, strictly-defined numeric types. On the right, a calm, confident, black-and-white photo of the 'GigaChad' character is labeled 'JS' (JavaScript). The text above him is simply 'number'. The meme humorously glorifies JavaScript's approach of having a single 'number' type for all numerical values, portraying it as an effortlessly superior solution. For experienced engineers, the joke is layered with irony, as they are well aware of the infamous floating-point precision issues (like 0.1 + 0.2 not equaling 0.3) that arise from this supposed simplicity

Comments

31
Anonymous ★ Top Pick JS having one 'number' type is like having one tool in your toolbox: a hammer. Sure, it's simple, but eventually, you're going to try and turn a screw with it, and that's when you'll truly appreciate the existence of screwdrivers
  1. Anonymous ★ Top Pick

    JS having one 'number' type is like having one tool in your toolbox: a hammer. Sure, it's simple, but eventually, you're going to try and turn a screw with it, and that's when you'll truly appreciate the existence of screwdrivers

  2. Anonymous

    Java bikesheds float vs double vs BigDecimal; C++ brandishes std::numeric_limits; JavaScript strolls by with one “number” and shrugs, “Precision was never on the backlog.”

  3. Anonymous

    After 15 years of explaining to junior devs why 0.1 + 0.2 !== 0.3 in JavaScript, I've come to appreciate that at least we only have ONE floating-point precision nightmare to deal with instead of choosing between float and double before discovering neither works correctly for money

  4. Anonymous

    JS has one number type and it's a double - which explains why 0.1 + 0.2 confidently asserts dominance as 0.30000000000000004

  5. Anonymous

    JavaScript developers: 'Why worry about integer overflow when you can just have floating-point precision errors everywhere?' Meanwhile, C++ devs are still debugging why their uint32_t wrapped around at 4,294,967,295 while simultaneously judging JS for thinking 0.1 + 0.2 === 0.3 is a reasonable expectation

  6. Anonymous

    Java: pick int/long/float/double; TypeScript: pick number - then spend Q4 explaining IEEE‑754, 2^53−1, and why finance just asked for Decimal128

  7. Anonymous

    C++: 17 ways to store a number, zero runtime surprises. JS: One 'number', infinite NaN debugging sessions

  8. Anonymous

    JavaScript resolved the int-vs-float bikeshed by standardizing on IEEE-754 doubles; the debate returns when user IDs pass 2^53-1 and finance asks where the pennies went

  9. Deleted Account 4y

    BigInt

  10. @gDanix 4y

    Num a => a

  11. @oleksandrst 4y

    0.2+0.1

    1. @kandiesky 4y

      https://betterprogramming.pub/why-is-0-1-0-2-not-equal-to-0-3-in-most-programming-languages-99432310d476

  12. @Vlasoov 4y

    parseInt(0.0000005)

    1. Deleted Account 4y

      5e7

      1. @affirvega 4y

        5e-7

        1. Deleted Account 4y

          Misspelled, oops

  13. @Knnknk72 4y

    Then there's Python. 😎

  14. @slnt_opp 4y

    Struct Protobuf

  15. @feskow 4y

    Everything here seems logical

    1. @emil_wislowski 4y

      even first two?

      1. @RiedleroD 4y

        …what the fuck, I see it now

        1. @emil_wislowski 4y

          mindfuck

      2. @feskow 4y

        Yes. I imagine they wrote something like this: function max(...) { let max_value = -Math.Infinity; for (let a of args) { if (a > max_value) max_value = a; } return max_value; }

        1. @RiedleroD 4y

          lol

        2. @dsmagikswsa 4y

          You are genius 👌🏻

    2. Deleted Account 4y

      Can you explain last one how you can get int from int-str?

      1. @RiedleroD 4y

        js likes to implicitly parse strings as ints numbers when it can

        1. Deleted Account 4y

          My c++ brain is mind fucked

          1. @feskow 4y

            int implicit operator - (const int& lhs, const string& rhs) { return lhs - std::stoi(rhs); }

        2. @dsmagikswsa 4y

          Yes. Fancy coercion

  16. @KP2020 4y

    PHP $

Use J and K for navigation