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
31Comment deleted
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
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.”
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
JS has one number type and it's a double - which explains why 0.1 + 0.2 confidently asserts dominance as 0.30000000000000004
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
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
C++: 17 ways to store a number, zero runtime surprises. JS: One 'number', infinite NaN debugging sessions
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
BigInt Comment deleted
Num a => a Comment deleted
0.2+0.1 Comment deleted
https://betterprogramming.pub/why-is-0-1-0-2-not-equal-to-0-3-in-most-programming-languages-99432310d476 Comment deleted
parseInt(0.0000005) Comment deleted
5e7 Comment deleted
5e-7 Comment deleted
Misspelled, oops Comment deleted
Then there's Python. 😎 Comment deleted
Struct Protobuf Comment deleted
Everything here seems logical Comment deleted
even first two? Comment deleted
…what the fuck, I see it now Comment deleted
mindfuck Comment deleted
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; } Comment deleted
lol Comment deleted
You are genius 👌🏻 Comment deleted
Can you explain last one how you can get int from int-str? Comment deleted
js likes to implicitly parse strings as ints numbers when it can Comment deleted
My c++ brain is mind fucked Comment deleted
int implicit operator - (const int& lhs, const string& rhs) { return lhs - std::stoi(rhs); } Comment deleted
Yes. Fancy coercion Comment deleted
PHP $ Comment deleted