Is there any difference I have to take care by using one of these comparisons or are they completly identical:
return !!(foo == 'bar')
return (foo == 'bar') ? true : false;
if (foo == 'bar') return true;
else return false;
Is there any difference I have to take care by using one of these comparisons or are they completly identical:
return !!(foo == 'bar')
return (foo == 'bar') ? true : false;
if (foo == 'bar') return true;
else return false;
The better one (not included in the list) is
return foo === 'bar';
All expressions return the same result, but because of ==
or ===
operators return a boolean value you can simplify the expression and have a more readable code.