Conditional code Flashcards
What is the basic building block of the “IF” statement in javascript
if ( . . . ) { . . .
}
( . . . ) represents ____________
If (The condition is true) {
Then do what is between this
}
( . . . ) = If this condition is true
{ . . . } represents _____________
If (The condition is true) {
Then do what is between this
}
{ . . . } = then do what is between these curly braces
( 1 )
Parentheses
[ 1 ]
brackets, oftentimes called square brackets
{ 1 }
curly braces
what is the purpose if braces, parenthesis, and brackets in coding?
They mark where a type of statement begins and ends
are braces, parenthesis, and brackets sometimes interchangeable?
NO, never change them nigga
brackets, braces, and parenthesis are always found in….
PAIRS
ALL conditions must boil down to….
true or false
how do you check for quality in a javascript condition?
==
double equal sign
If ( a==99) { execute this command
}
why is == a quality check and not one equal sign?
*Why use:
If ( a==99) { execute this command
}
and NOT
If ( a=99) { execute this command
}
because 1 equal sign SETS a value. a==99 means CHECK if a==99, and a=99 means a IS 99
If ( a==99) { execute this command
}
If ( a=99) { execute this command
}
how do you check inequality? that is check if a is NOT some variable
If ( a!=99) { execute this command
}
code block
several statements all grouped together, normally with the use of braces, parenthesis, or brackets.
how many lines if “IF” statements can javascript understand?
theoretically, infinite…
Why don’t we want to use too many if statements? What are other options?
It can become difficult for a human to understand. We can use functions or switches instead.
equality is used
when we want to check one variable against another
If ( balance == 10000) {Some command
}
the == operates as the equality operator
single “=” equal sign is known as the ___________ operator
assignment operator
you are telling javascript what you want some variable to be
double “==” equal sign is known as the ___________ operator
equality operator
you are asking javascript to check if the value of one variable is the same as another and to produce a true or false
triple “===” equal sign is known as the ________ operator
strict equality operator
a more “strict” version of ==
var a = 123; var b = "123";
if ( a == b ) { alert("Yes, they ARE equal"); } else { alert("No, they're NOT equal"); }
**Will this alert yes, or no?
*NOTE double equal sign
Yes
123 is the same as “123”
var a = 123; var b = "123";
// equality check if ( a === b ) { alert("Yes, they ARE equal"); } else { alert("No, they're NOT equal"); }
**Will this alert yes, or no?
*NOTE triple equal sign
No
123 is a number and “123” is a character string
How do you do the not equal to operator to check an equality?
(a != b)
how do you use the strictly not equal to operator?
(a !== b)