DEV Community

[Comment from a deleted post]
Collapse
 
ironcladdev profile image
Conner Ow

I tried what you did and this:

var num = 0;
num++;
var result = num++;
if(result) {
  console.log('Number');
} else {
  console.log({ result, num });
}
Enter fullscreen mode Exit fullscreen mode

...and That answered my question. So what happens is if the number incremented by any value, the result will be true.

Collapse
 
vonheikemen profile image
Heiker

Every number except 0 and NaN is considered a "truthy value". And if something is "truthy" then it pass the evaluation of the if statement.