[Vuejs]-Why does this equal true

3👍

In JS, as well as in most of programming languages, single “=” operator is used to assign one value to another. Thus, doing attachRed = !attachRed you’re simply reassigning the value of attachRed. When you reassign the value of any variable, the return is new value. If you want to compare two values, use either == or ===.

2👍

The ! operator means “not”. So if the value of attachRed is true, then !attachRed means “not true” (which of course means “false”). If the value of attachRed is false, then !attachRed means “not false” – so, “true”.

Leave a comment