- Review
- Types
- Variables
- Variables
- Declaration & Assignment
- Case Sensitive
- Valid/Invalid variables names
- Must begin with a letter, $, or _
- Can contain letters, digits, underscores, and dollar signs.
- Reserved words (like JavaScript keywords) cannot be used as names [http://www.javascripter.net/faq/reserved.htm]
- Fun tool: JavaScript variable name validator
- Boolean type
- Boolean comparison operators
- comparison (==, <, <=, >, >=, !=)
- Type coercion Exercise
- Type coercion
- Strict (non-coercing) boolean comparison operators
- (===, !==)
- Boolean logical operators
- and (&&)
- or (||)
- not (!)
- Creating a hello world file
- console.log
- comments
- Single line comments
- Multi line comments
- Using comments to plan
- Have an error in a file
- Printing exercise
- if statements
- Truthy and Falsy
Run the following expressions in a JavaScript REPL console, such as the immediate window in Cloud 9.
Were the results what you expected?
If not, which ones gave different results than expected?
true == true;
true == false;
true != false;
0 == 0;
0 == "0";
"0" == 0;
true == "true";
false == "false";
true == 1;
false == 0;Remember that a boolean expression evaluates to either True or False. What do the following boolean expressions evaluate to? Remember that you can check what they evaluate to by inputting them into the node JavaScript console
5 < 105 <= 5.010 - 1 > 33 * 1 - 1 == 1 + 15.0 / 2 == 5 / 2"Bob" == "Alice"5 == "5"5 === "5"5 < "hello""hello" < 5
There are only a few possibilities with logical boolean operations. The best thing to do is memorize them. Test your knowledge with this
- true && true = ?
- true && false = ?
- false && true = ?
- false && false = ?
- true || true = ?
- true || false = ?
- false || true = ?
- false || false = ?
- !false
- !true
Run the following expressions in a JavaScript REPL. Don't worry if there are bits of the code you don't understand yet.
Were the results what you expected?
If not, which ones gave different results than expected?
if ("") {
console.log("An empty string is true?");
}
if (!"") {
console.log("An empty string is false?");
}
if (!0) {
console.log("Zero is false?");
}
if (42) {
console.log("The number 42 is true?");
}