Javascript contains several categories of operator, including Assignment, Comparison, Arithmetic, Bitwise, Logical, String, Conditional (ternary), Comma, Unary, and Relational. Most operators are binary, requiring two operands.
Assignment operators take a variable, do math to it, and make the resulting value the new value of the variable. Chains of assignment operators on a single line should be avoided.
Comparison operators take to variables, determine a certain relationship between them, then return a boolean output.
A for
loop is structured as follows:
for ([initialExpression]; [conditionExpression]; [incrementExpression])
statement;
It executes in the following order:
- Execute the
initialExpression
. - Check the
conditionExpression
. If false, leave the loop. - Execute the
statement
. If there are multiple statements, use a{block statement}
to execute them all. - Execute
incrementExpression
. - Repeat back to step 2.
A while
loop is structured as follows:
while (conditionExpression)
statement;
It executes in the following order:
- Check the
conditionExpression
. If false, leave the loop. - Execute the
statement
. If there are multiple statements, use a{block statement}
to execute them all. - Repeat back to step 1.