Javascript is cursed
I hear a lot of moanings on JS inconsistency. Complete bollocks it is.
Here you we go with a pure and blessed C++ example.
// will set more precise precision and disable scientific output cout << fixed << setprecision(20) << (0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1) << endl;
The result will be not 1 as expected but 0.99999999999999988898 because operations with types double and float are calculated approximately.
And the second example
C++ inherited from C the ability to add simple string literals to numbers. In this case, the code compiles without errors, but when run, an unusual result is obtained, which can even lead to the crash of the program:
string s = "Hello" + 1; // Variable s will have the value "ello" string q = 1 + "Hello"; // Variable q will also have the value "ello" // Here the behaviour of the program will be undefined, // since the numeric argument is longer than the length of the string: // string e = "Hello" + 10000;
So behave yourselves and enjoy JS you bastards!