1. What are expressions and statements

expression

  • 1 + 3An expression, called an expression, is a calculation to get a return value.

statements

  • This is a statement, and a statement is an operation to accomplish something, such as a line assignment statement.

var a = 1

2. Rules for identifiers

The first character can be any Unicode letter (including English and other languages), as well as the dollar sign ($) and underscore (_).

In addition to Unicode letters, dollar signs, and underscores, the numbers 0-9 can be used for the second and subsequent characters.

3. If else statement

  • ifYou can have a block of code followed by oneelseCode block that represents the code to execute if a condition is not met.
  1. if (m === 3) {
  2. // The statement to execute when the condition is met
  3. } else {
  4. // The statement to execute if the condition is not met
  5. }
  • The code above determines whether the variable m is equal to 3 and executes an if block if it is, and else block otherwise.

  • More than the if… Else statements can be joined together.

4. While for statement

The while loop

  • WhileThe statement consists of a loop condition and a block of code that executes over and over again as long as the condition is true.
  1. While (condition)
  2. Statements;
  3. / / or
  4. A while (condition) statement;

The for loop

  • forStatements are another form of a loop command that specifies the start, end, and termination conditions of a loop. Its format is as follows.
  1. For (initializes the expression; Conditions; Incrementing expression)
  2. statements
  3. / / or
  4. For (initializes the expression; Conditions; Incrementing expression) {
  5. statements
  6. }

5. Break the continue statement

  • breakStatements andcontinueStatements are jumps that allow code to be executed out of the existing order.
  • breakStatements are used to break out of a code block or loop.
  • continueStatement is used to immediately terminate the loop, return to the head of the loop structure, and start the next loop.

6. The label statement

  • The JavaScript language allows statements to be preceded by labels, which act as locators for jumping to any point in the program
  • Tags are usually associated withbreakStatements andcontinueStatements are used together to break out of a particular loop.