False, True


#1

Hi,

I got task:

a == false
!a == false
a == !a

As I understund, const a should be equal to false, because:

a = 10
a == false                     // true
!a == false                    // false
a == !a                        // false

Could somebody explain me this?
Thank you in advance.


#2

I'm not sure what you're getting at here. a is equal to 10, as you set it to ten.

Also:

a = 10
a == false                     // false
!a == false                    // true
a == !a                        // false

Did I miss something?


#3

Nope, it equals true (only false, null, undefined, 0, and '' are falsy)


#4

You may find this article helpful:

Hint: The answer is a combination of the values @Dormilich mentioned... so much for the loose equality comparison. :-P


#5

Thank you :slight_smile:


#6

As a result, it's best to stay away from the loose equality comparison and stick with the strict triple equals === comparison instead.


#7

Unless of course you want to write orthodox JS... :-)


#9

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.