If(!programming): What Does It Exactly Mean? - Codecademy
Maybe your like
Hello, first time writing here :)
I think I’ve read most of the questions and answers about this topic, but I think I still don’t understand. This code is working, but I don’t understand the !programming.
var programming = false; var happy = function() { if(!programming) { return(true); } else { return(false); }; };But first I have another question. Up until now, in the exercises, I would declare a variable and assign it the value true, and then write something like if(varName) which would mean if(varName === true). My question is: was that because the variable had been assigned the value true or because if(varName) means if(varName === true)?
And, the second question: how would you translate if(!programming) to regular English? I know that if programming = false, then !programming = true. But how does that make sense inside the if statement? Does it mean if no programming, that is to say, if programming is false?
ADDED I wrote this to figure out the first question. I guess is the same as before, but simpler.
var programming = false if(programming) { console.log(1); } else { console.log(2); };This prints 2, so I guess if(varName) means if(varName=== true)?
Answer 5411c73f80ff33353d00284e
0 votesPermalink
Actually the argument of if() has to be a boolean expression or in other words evaluate to true or false. You could put whatever you want inside, even if that does not makes sense, provided it results into a boolean expression. Following are valid boolean expressions:
true varName varName=== true ! varName
The way to understand the “!” operator is to think that as a “not”, so when you ask if(!programming) is a way to express “if it does not program do such”….
5 comments
Thank you, thank you!
i dont get it. what do you mean “If it does not program do such”
if i set var programming = false; what does if (programming) mean and what would if(!programming) mean? would if (!programming) in this case , with it set as false mean if(programming===!false===true) ?
ah i think i get it sorry for talking that much
talking that much helps the rest of us understand it too :)
Answer 5412d129282ae33aff0017f5
0 votesPermalink
The ! is the not operator, so it means if “not false” which means true or if “not true” which means false. Here is a list how other values evaluate to booleans if used in a condition: http://www.sitepoint.com/javascript-truthy-falsy/
And last but not least varName === true and varName behave the same way so you can use the shorter version as you can see by getting through the possible results:
if varName is true and varName === true is true if varName is false then varName === true is falseSo to see varName === true has for any choices of varName the same value as varName itself.
Answer 54248282282ae3eca60001e4
0 votesPermalink
The way you can interpret it like this: When you enter
hey var = true; if (hey) // is a way of if saying hey === true { console.log (“hello”); // The condition is true so you’ll print this post } else { console.log (“bye”); }
If the condition is false: hey var = false; if (hey) // is a way of saying if hey === true { console.log (“hello”); } else { console.log (“bye”); // The condition is false so you will print this message }
But if you enter:
hey var = true; if (!hey) // You’re telling the system that hey === true but want to change it to false or vice versa if originally you condition is hey === false change it to true { console.log (“hello”); } else { console.log (“bye”); //As initially var === true you will change it to false and will print this message }
1 comments
its var hey = true not hey var = true. var is the keyword to get a variable followod by the name of that variable you want to create. The rest is good.
Popular free courses
- Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.- Checker DenseBeginner Friendly.4 Lessons
- Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.- Checker DenseBeginner Friendly.11 Lessons
- Free course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.- Checker DenseBeginner Friendly.6 Lessons
Tag » What Does It Mean If
-
IF | Meaning, Definition In Cambridge English Dictionary
-
What Does If Mean? | Best 26 Definitions Of If - YourDictionary
-
What Does If Mean?
-
If Definition & Meaning - Merriam-Webster
-
If Definition & Meaning
-
If Definition And Meaning | Collins English Dictionary
-
What Does IF Stand For?
-
What Does “if” Actually Mean? - Quora
-
What Does The Word 'if' Mean? - Quora
-
If And Only If - Wikipedia
-
What Does It Mean When You Dream About Money? - N26
-
What Do You Do? How Do You Do? | Britannica Dictionary
-
What Does It Mean If A Disorder Seems To Run In My Family?
-
What Does It Mean When You Dream About Someone Dying?