There Are Many Ways To Say No
<p>In this video we'll take another look at working with not (!): so far we used our '!' operator while comparing <a href="/courses/video/5/157/Using-Variables.html">variables</a>. (a!=b). In this video we'll look at another way to work with negative equations in ActionScript - !(a==b)</p> <p>After learning about AND (&&) and OR (||) operators, now it is time to understand what a NOT operator is. A NOT operator can be defined as the negation of any statement. Most of the <a href="/courses/video/4/33/Numbers-And-Basic-Math.html">math</a> text books have the symbol (~) for the NOT operator, but in programming we use the exclamation mark (!) to denote the NOT logical operator.</p> <h2>NOT Operator (!) (Complement of a statement)</h2> <p>The NOT operator gives the complement of any statement when it is applied. For example, if we write <b>trace(!true)</b>, the answer would be false because in terms of <a href="/courses/video/5/162/Boolean.html">Boolean</a> values, false is the compliment of true. This is the reason why a NOT symbol before an <a href="/courses/video/7/55/Equality.html">equality</a> sign checks for <a href="/courses/video/7/199/Explicit-Equality.html">explicit</a> inequality (!==). As we get familiar with this operator, we'll understand how this operator is used in various forms. Here we'll list a few of these before moving to the <a href="/courses/video/7/60/Null-vs-Undefined.html">next video</a>.</p> <h2>Various Ways To Use NOT operator (!)</h2> <p>Firstly, we know that <b>trace(!true)</b> is false. But if we write <b>trace(!true==false)</b>, this equation is split before giving the final result, <b>trace(false==false)</b> which is true of course. The same equation can be written like this as well, <b>trace(!(false==true))</b>. Here the result is same as the equation simplified to <b>trace(!(false))</b> which gives the result as true. Consider another example <b>trace(!(0))</b>. We are using extra <a href="/courses/video/8/65/Brackets.html">brackets</a> just to avoid mixing up variables which may lead to confusion in big equations. This equation is converted to a <a href="/courses/video/5/162/Boolean.html">Boolean form</a>, <b>trace(!(false))</b>, since 0 is the value used for false. So the final result of <b>trace(!0)</b> is true.</p> <h2>NOT Operator (!) using Variables</h2> <p>There are a few important things to note while using the NOT Operator with <a href="/courses/video/5/157/Using-Variables.html">variables</a>. For example, take a variable isTrue which has a Boolean value 'true' assigned to it. We can write <b>trace(!isTrue)</b> to find the compliment of true which is false. But when we use isTrue further in the program, its value is <b>not</b> altered permanently due to changes made by the NOT Operator. The change is temporary for the particular line and the variable never loses its original assigned value. But if we want to change the value permanently, we must use the assignment operator along with NOT Operator. For instance, when we write <b>isTrue = !isTrue</b>, this will assign a value to the variable which is its compliment. In this case the value of <b>trace(isTrue)</b> changes from true to false.</p>