I'm messing with code that someone else wrote and I saw that he writes like this
if(i === true)
Is there a difference if I do it this way?
if(i)
I'm messing with code that someone else wrote and I saw that he writes like this
if(i === true)
Is there a difference if I do it this way?
if(i)
The first if statement is checking for exact equality, and will only run if i
was exactly equal to true.
The second one is checking for whether i
is truthy, which means the if statement would still run if i
was something other than things such as null
, undefined
, or an empty string.
Using the comparison operator will return true if i is boolean true, but just having i will return true for any truthy value I.E: positive integers, non-empty strings, etc