!! Double Bangs

There are several ways to determine conditional logic in Javascript. The most common across all languages would be the classic IF/Else/Else If logical statements.

The next common would be ternary expressions. These expressions return a value of true/false and execute logic based on the condition.

name = isName === 'Brian' ? true : false

if isName is ‘Brian’ then name would be true, otherwise it’s set to false.

Another way to check and assign a result is with double bangs.

userLoggedIn = '' isUserLoggedIn = !!userLoggedIn

Above, the double bang will return false.

Leave a Reply

Your email address will not be published. Required fields are marked *