Js determines whether a number is a positive integer?

if (number-0) | 0)! = = number-0) {/ / enter whether the purchase quantity is a positive integer

nextBtn.disabled = true;
nextBtn.innerHTML = "";
return;

}
see this code in the book (number-0) | 0)! = number-0
negative number or 0 is not a negative number? Is
written wrong

if I write something wrong, how can I write it according to the way this book is written?

ask the boss to help! Thank you

Mar.20,2021

original answer: just to judge that number is a positive integer? number > 0 & & Number.isInteger (number)

make explanations and corrections according to the author's intention:

the key to your judgment lies in the bitwise or operator. If number is an integer, such as 10, then 10 | 0 = = 10 , but if it is a decimal, or the result is also the integer 10.1 | 0 = = 10 . If there is a number-0 operation at the same time, if a string such as number = = 'abc' number-0 = = NaN , then bitwise and NaN | 0 = = 0 will avoid reporting an error.

back to your condition, if number is an integer, then the condition is not true, there is no need to prompt the user to enter the correct quantity, if the number is a decimal, then the condition holds, prompting the user to enter the correct quantity. This condition will not judge whether it is positive or negative, but whether it is an integer or not. If number is a string like '123', the condition is not true; if it is a string like 'abc', the condition is true.

conclusion: there is nothing wrong in the book. This condition is true when the user enters a decimal, non-numeric string.

if you have to judge > 0, you can write

like this.
  

positive integer, actually very simple, only need three steps if, first, it is not a non-digital isNaN, second, it is an integer, after rounding processing, compare whether it is the same equivalent, if it is an integer, otherwise it is not an integer, three, it is not negative, that is, greater than 0. That's it. Of course, if you want to write it succinctly, you can study it.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3c4e8-44692.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3c4e8-44692.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?