
GitHub - denysdovhan/wtfjs: A list of funny and tricky JavaScript ...
A list of funny and tricky JavaScript examples. JavaScript is a great language. It has a simple syntax, large ecosystem and, what is most important, a great community. At the same time, we all know that JavaScript is quite a funny language with tricky parts.
Avoiding problems with JavaScript's weird decimal calculations
Math.round(0.2 * X + 0.1 * X) / X === 0.3 // true where X is some power of 10 e.g. 100 or 10000 - depending on what precision you need. Or you can use cents instead of dollars when counting money:
JS WTF with Math - HackerNoon
Sep 26, 2017 · Let’s ride on weirdness with JavaScript Math. WHAT? max is not bigger than min? NO 😱 but there’s a reason for it. By definition Math.max([value1[, value2[, ...]]]) returns the largest of the given numbers. However, when no arguments are provided it returns the minimum possible value, which is -Infinity.
JS WTF with Math. Let’s ride on weirdness with ... - Medium
Jan 29, 2018 · Let’s ride on weirdness with JavaScript Math. WHAT? max is not bigger than min? NO 😱 but there’s a reason for it. By definition Math.max([value1[, value2[, ...]]]) returns the largest of the...
JavaScript is Weird (all explanations are in the comments)
Mar 19, 2022 · {} is interpreted as an empty code block. The result of + "x" is NaN, because "x" cannot be converted to a number. Math.min() is a function that returns the lowest-valued number passed into it. The result of that function is Infinity if no parameters are provided.
A humorous list of JavaScript oddities : r/programming
Aug 27, 2011 · However, Javascript uses IEEE754 double floating-point numbers, which are based on the "extended reals" - basically you just take the normal real numbers and add positive/negative infinity. So the minimum and maximum numbers (and hence the max/min identitys) are -Inf and +Inf.
Weird Math in JavaScript - Medium
Jun 14, 2024 · That seemingly outdated piece of technology is actually better at math than Node.js. A well-known example is: I won’t dive into the technical details of why this happens. Instead, I’ll explain two...
Weird Javascript Behaviour: Floating Point Addition giving the …
Jun 24, 2009 · For example, 001010 would be 0 * 1/2 + 0 * 1/4 + 1 * 1/8 + 0 * 1/16 + 1 * 1/32. This is a rough example of why floating points cannot be exact. As you add precision (float -> double -> long double) you get more precision to a limit.
Understanding JavaScript’s Weird Decimal Calculations
Apr 8, 2019 · The classic example that everyone keeps referring too is the following calculation: 0.1 + 0.2 === 0.3 // this is false! because 0.1 + 0.2 = 0.30000000000000004. What? Is this another quirk of...
Weird Parts of JavaScript — Math Operations
May 6, 2020 · In this article, we’ll look at the weird parts of the mathematical operations of JavaScript so that we won’t fall into traps that cause bugs. undefined and the Number Function The JavaScript Number function is used to convert anything to a number.
- Some results have been removed