Please read the explanation before clicking...
=> | {{x}} |
Script:
<button ng-click="x = !x"> This button toggles the Boolean value of x</button>
{/{x}/}
Explanation
As you recall from JavaScript, a value is always a Boolean true
unless it is zero,
false, null or undefined in which of these cases the value is false.
At first, x is a Boolean false (from x = !x). However we don’t see it displayed on the screen because we haven’t clicked on the button.
When we click the first time, x gets assigned to !x which is the opposite of x and since x was originally assigned to false ( from the original !x) it becomes a Boolean true, as we now see on the display.
When we toggle the switch again, x becomes the opposite of what it is at the moment and so it displays false.
And so on.
This is an important concept to realize in order to understand our next project.