M
M
mib2016-02-10 19:01:42
JavaScript
mib, 2016-02-10 19:01:42

In a java script, a false condition is sometimes met, how can this be?

Sometimes there are such incidents:
89234-clip-39kb.png
The condition should not work, but it works, while the execution of the body of the condition skips one command.
It seems that the parser does not see curly braces after the condition, so one command is skipped - the condition works correctly for the first command after the condition
Maybe someone has come across such cases? How to fight?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2016-02-10
@nazarpc

This may occur due to the fact that decimal floating point numbers under the hood still have a binary representation, and therefore the number may not be 20.0, but, for example, 20.000000001, and then 20.000000001 - 20 will be 0.000000001, which is greater than zero .
Operate with whole numbers in such cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question