28 Conclusion part 2


#1

if (“6+2=8”);
{
console.log(“I finished my first course!”)
}
else
{
console.log(“nope”)
}

What’s wrong with this ?


#2

==== 1 =======
The semi-colon is used by Javascript to express an END-of-Statement
like

if (“6+2=8”);

the Javascript Interpreter will see it as the END of the IF-statement
you will therefor run into the error that the ELSE-statement is NOT recognized as being part of an IF-ELSE statement.

===== 2 ========
In your if (condition)
Normally you use a comparison using one or more logical operators…
which will then evaluate to a true or false
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators

You are using a string
then the Javascript will create a truthy or falsy

  • A falsy value is a value that translates to false when evaluated in a Boolean context
  • In JavaScript, a truthy value is a value that is considered true when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, “”, null, undefined, and NaN).

https://developer.mozilla.org/en-US/docs/Glossary/Falsy
https://developer.mozilla.org/en-US/docs/Glossary/Truthy


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.