Is there a significant performance or any other difference when using x < 1
over x <= 0
in javascript?I'm wondering why <= even exists if you can always achieve the same with < and one greater/lesser number.
Asked
Active
Viewed 64 times
-3

yolst
- 86
- 4
-
4Take x = 0.5 for example... – Aioros Oct 09 '20 at 15:40
-
1Ignore performance. Premature optimisation is the root of all evil. With that asaid, why shouldn't it exist? What's the problem of having a more expressive token in the language? If I want "at most six" it's easier to write `x <= 6` rather than mentally have to make it "at most one less than seven". – VLAZ Oct 09 '20 at 15:40
2 Answers
0
There's no difference in any real-world sense. If you want you can read this post x > -1 vs x >= 0, is there a performance difference

zerbene
- 1,249
- 2
- 7
- 21
0
The speed is negligible.
Actually both works like the same, if you have integer values.
A better approach is to take condition which works for floats as well without having to change the condition. This prevents to search for weird results later, if the condition is not sufficient commented.

Nina Scholz
- 376,160
- 25
- 347
- 392