More on controll flow (Not)


I don't understand this lesson it should teach me the operator ! , i realize what it does but i want to know how it can be implemented or why is it useful at all .

My code : // Declare your variables here!
var programming = false;

var happy = function() {
// Add your if/else statement here!
if (programming === false) {
return true
else {return false}

And the task was to declare programming as false and return true if it was . So what was the point of this lesson ?
Would this work : var programming = true;
if (!programming)


! negates a Boolean, and if applied to an expression, the expression is converted to a Boolean then negated.

// on Booleans
console.log(!true);              // false
console.log(!false);             // true

// on expressions
console.log(!("A"));             // false
console.log(!(1));               // false
console.log(!(""));              // true
console.log(!(0));               // true
console.log(!(function(){}));    // false

var programming = false;
var happy = function() {
    if (!programming) {    // programming is a Boolean.
        return true;
    } else {
        return false;

The value in programming is still false. NOT does not alter the orginal value. It creates a separate temporary (transient) object, evaluates it and negates it. The conditional only sees the final yield.


But what is the point if i cant just : if (programming === false) ?


This question misses the point entirely. Oh well, no need to trouble over this. It is the only lesson where NOT comes up. If it is too much to wrap your head around then I guess we can just move on. Eventually you will see the logic.