DEV Community

Discussion on: What is the oddest JavaScript behavior?

Collapse
adam_cyclones profile image
Adam Crockett

There is one that I can't remember precisely, but JavaScript cannot add 2.637 or something like that the result is wrong. I will have to look this up.

Collapse
keptoman profile image
mlaj

Adding floats. It won't give the right answer. It's a common problem in programming languages.

Collapse
adam_cyclones profile image
Adam Crockett

Yeah I had a suspension that was the case. Still it's odd and it doesn't not affect JavaScript so I'm technically correct. 🙃

Collapse
kspeakman profile image
Kasey Speakman • Edited on
console.log(.3);
// 0.3

console.log(.1 + .2);
// 0.30000000000000004
Collapse
adam_cyclones profile image
Adam Crockett

That's the one! Thanks!