x = 7
=
and assigns the value 7 to the variable x3 + 4
+
operator to add 3 and 4 to produce the value 7const z = 3 + 4
) or its result will be immediately discarded=
assigns a value to a variablelet x = 10;
assigns a value of 10 to variable x+
adds numbers*
multiplication operatoroperand1 operator operand2
operator operand OR operand operator
Logical *&& logical and; | logical or; ! logical not* |
const obj = {};
-> obj.x = 3; console.lob(obj.x); // prints 3
or console.log(obj); // prints x: 3.
EX: const key = "y"; obj[key] = 5; console.log(obj[key]); // prints 5. console.log(obj); // prints { x: 3, y: 5 }
for
loop repeats until a specified condition evals to false. JS loop is similar to Java and C loopfor
statements look as follows:
for
loop executes the folloing occursinitialization
, if any, is executed. This ususally initializes one or more loop counters, but the syntax allows an expression of any degree of complexity. Can also declare variablescondition
expression is evaluated. If the value of condition
is true, the loop statement executes. Otherwise, for
loop terminates. If condition
expression is omitted entirely then condition is assumed to be truestatement
executes. To execute multiple statements, use a block statement ({})
to group those statementsafterthought
is executedwhile
statement executes its statements as long as a specified condition evaluates to true
. A while
statement looks likewhile (condition) statement
condition
becomes false
, statement
within the loop stops executing and control passes to the statement following the loopstatement
in the loop is executed. If condition returns true
, statement
is executed and the condition
is tested again. If the condition returns false
, execution stop, and control is passed to the statement following while.