Boolean and If-Statement
Boolean and If-Statement
Numbers and
Strings
Boolean and if-statement in
javascript
Grade 9
Learning target:
•define Booleans and Conditional Statements
•Apply Booleans and Conditional Statements in
JavaScript and use them to store and
manipulate data in their programs.
Let’s think!
How do Boolean values and the 'if' statement
influence the logic and flow of your code, and how
can mastering these concepts enhance your ability to
design efficient and effective algorithms?
What is Boolean?
Boolean is a datatype
that returns either of
two values i.e. true or
false.
Boolean in javascript
In JavaScript, Boolean is used as a
function to get the value of a variable,
object, conditions, expressions, etc. in
terms of true or false.
console.log (4<5);
Let’s practice!
Open SublimeText and create and HTML document with a
filename, boolean.html.
Type this inside the body:
What are you going to do to make the value true?
Let’s practice!
Why is it true when the one is a number, and the other one is a string?
Double equal sign converts value in the same type. To solve this, you need to use a triple
equal sign so that JavaScript would tell us that the two values are not the same.
Comparison operators
• Equal to ===
• Greater than >
• Lesser than <
• Greater than or equal to >=
• Less than or equal to <=
• Not equal to != =
Order of operations
1. ()
2. * /
3. + -
4. Comparison operators
Let’s practice
1. Type this:
What is an If-Statement?
In JavaScript, an "if statement" is a control
structure used for conditional execution of
code. It allows you to specify a condition,
and if that condition evaluates to true, the
code block associated with the if
statement is executed.
Analogy
Let’s practice