lundi 26 janvier 2015

JavaScript evaluates differently every time

There is a weird problem:


I got the window and the document height on a resize event. With this both numbers I tried to do something with an if/else statement. Very basic but it did not work, so I logged the data:


Inside the if part I logged "TRUE [number one] >= [number two]" inside the else part I logged "FALSE [number one] >= [number two]". This was triggered by a window resize event. Then I resized the window only horizontally, so the height values did not change. With two identical numbers I assumed that it logs always the TRUE part but output is:



[...]
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
TRUE 548 >= 548
FALSE 548 >= 548
[...]


The type of the value is always "number", it is always an integer, no float. "Tested" in IE9 and FF35.


Can someone explain what happens there? How can I avoid this behaviour?


Thank you!


Aucun commentaire:

Enregistrer un commentaire