0
JS, 8/8, 3 question - please somebody explain it to me.
SOS! I don't understand it. People please help.
8 Respostas
+ 10
false
+ 5
Result for 'var1 && var2' if var1= true and var2 = false?
Conditionnals are very much important...
You would be adviced to go back and re-learn this part: it's not so hard... and really necessary.
However, i'll try to get you basics:
- a condition implies a test: if something is true do one thing, else do another... 'something' is the conditional test. ( ie: if a > b )
- you may needed multi-condition testing, so there many way to do it: if condition1 then if condition2... but the nested if can quickly grow too much up, while we can combine condition with conditionals operators: var1 && var2 is read 'var1 and var2", as well as 'condition1 and condition2'. So, the:
if ( var1 && var2 )
... is the same as:
if (var1) {
if (var2) {
/* here you see that the var1 condition must be true for test var2 running,
so this block of code is only running if ( var1 is true AND var2 is true )
}
}
The other wellknown comparison operateur is the OR operator, which is represented by a pipe pair ( || )...
+ 3
What's the result of the expression var1&&var2, if var1=true and var2=false?
i don'y understand why false print.
+ 2
False
0
The thing that puts me on the wrong foot is that both variables and the conditional are written without spaces.
0
False
0
var1 is true and var2 is true then the result is true because all the expressions are true
var1 is true and var2 is false then the result false because not all the expressions are true
0
AND (&&) is a logical operator used when both conditions are true and must be true. So since var2 condition is assigned false in the question, the answer will be FALSE.