Why is this NULL variable truthy?

  • A+
Category:Languages

I've known null to be falsy. Then why does it act as if it is a truthy?

var status = null;  console.log('status:', status);  if(!!status) {   console.log('status is truthy');   // it should not print }  if(!!null) {   console.log('null is truthy');   // it should not print }

 


The issue is there is already a window.status, with which you conflict. It has setters that always make it a string, which causes your problems.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: