‘booleanVar == false’ VS ‘!booleanVar’ in coldfusion
In coldfusion booleanVar == false
and !booleanVar
is not one. If you have a variable, If the boolean value is set like var booleanVar = true;
or var booleanvar = false;
then it does the same.
But if the value of this variable is set at any time blank e.g. var booleanVar ="";
. Then ! booleanVar
it’s give error in if condition e.g. if( ! booleanVar )
. Because it just checks boolean vlaue.
But using ‘booleanVar == false’ it’s check not only the Boolean value it’s also check blank value. If there is a blank then it does not give the error. Since the value is blank, this condition will not match. e.g. if( booleanVar == false )
.
This is most possible if the data comes from the database. It may come to boolean, null or blank values.