1. What are expressions and statements
  2. Specification of identifiers
  3. If the else statement
  4. While for statement
  5. break continue

label

1: The difference is that a statement performs an action and an expression produces a value. This means that an expression must produce a value when executed, whereas statements do not necessarily produce a value. Statement is primarily used to perform action 2: Identifiers can contain only letters or numbers or underscores (” _ “) or dollar signs (” $”), and cannot begin with a number. Identifiers differ from strings in that strings are data and identifiers are part of code 3:


var shoppingDone = false;

if (shoppingDone === true) {
  var childsAllowance = 10;
} else {
  var childsAllowance = 5;
}
Copy the code

4:

for (var i = 0; i < 100; i++) {
  ctx.beginPath();
  ctx.fillStyle = 'rgba (255,0,0,0.5)';
  ctx.arc(random(WIDTH), random(HEIGHT), random(50), 0.2 * Math.PI);
  ctx.fill();
}
Copy the code
let b = true;
while (a) {
console.log("true")}Copy the code

5: During the loop, you can use the break statement to break out of the current loop

6:

  var i, j;

    loop1:
    for (i = 0; i < 3; i++) {     
       loop2:
       for (j = 0; j < 3; j++) {    
          if (i === 1 && j === 1) {
             continue loop1;
          }
          console.log('i = ' + i + ', j = '+ j); }}// Output is:
// "i = 0, j = 0"
// "i = 0, j = 1"
// "i = 0, j = 2"
// "i = 1, j = 0"
// "i = 2, j = 0"
// "i = 2, j = 1"
// "i = 2, j = 2"
Copy the code