Negative numbers are Truthy or Falsy Values?

4090 views javascript
4

a simple question I want to ask is what are the negative values equal to? From a console, I see they are neither true nor false. So what are they actually?

I tried this statement

console.log(-1 == false)

and it gives me false Output

I also tried

console.log(-1 == true)

It also gives me false.

Console Screen

So what are negative values actually are if they are neither true nor false.

answered question

Only 0 is falsy, other numbers are truthy.

You should use console.log(Boolean(-1) == true) to determine truthiness or falsiness

Or force it to convert to boolean by negating twice !!-1

1 Answer

12

Any number greater than or less than 0(not equal as 0 is falsy) is truthy in javascript. You can check this my making a simple example, In the example below the if statement evaluates to true and console logs 2.

if(-1){
  console.log(2);
}

posted this

Have an answer?

JD

Please login first before posting an answer.