Check if value is not greater / less than zero - Javascript

How to check if value is not greater or less than zero using Javascript ?

I tried to use the following solution for "not greater than zero" condition, but it is not working.

if ( !value>0 && otherValue==1 ) { alert('Ok'); }
0
give a positive ratinggive a negative rating
23 Oct 2021 at 05:24 PM
Hi,

To make the "is not greater than zero" condition work correctly in javascript, you have to add brackets (parentheses) there. The code with logical NOT operator used, should look like:

if ( !(value>0) && otherValue==1 ) { alert('Ok'); }
0
give a positive ratinggive a negative rating
24 Oct 2021 at 10:56 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us