102-Learning journal
This project is maintained by cmboell
You can evaluate a situation by comparing one value in the script to what you expect it might be. The result will be a Boolean: true or false. Comparison operator examples:
==
===
!=
!==
>
>=
<
<=
Comparison operators usually return single values of true or false. Logical operators allow you to compare the results of more than one comparison operator. Logical operator examples:
&&
||
!
Logical expressions are evaluated left to right. If the first condition can provide enough information to get the answer, then there is no need to evaluate the second condition. If the first condition is false the entire expression is false.
Loops check a condition. If it returns true, a code block will run. Then the condition will be checked again and if it still returns true, the code block will run again. It repeats until the condition returns false.
There are 3 common types of loops:
A for loop uses a counter as a condition. This instructs the code to run a specified number of times. The condition is made up of 3 statements:
var i = 0;
. The variable is only created the first time the it is run.i < 10;
. If the value was initially set at 0 it will run 10 times before stopping.i++
. One is added to the counter using the increment (++) operator. It is also possible for loops to count downwards using the decrement operator(–).