Basic statements in JavaScript

Tram Ho

JavaScript Program

A computer program is a list of instructions executed by the computer. In programming languages ​​these instructions are called statements. A JavaScript program is a list of statements

Basic Commands in JavaScript

JavaScript statements include

  • Values
  • Operators
  • Expressions
  • Keywords
  • Comment

Semicolons (semicolon) in JavaScript

The statements in JavaScript are separated by semicolons.

Semicolon hides the end of statements in JavaScript

For example

We can write multiple statements on the same line if they are separated by semicolons.

Whitespace in Javascript

JavaScript does not care about the spaces in the code, so we can add spaces to make the code more readable.

For example

Command Blocks in JavaScript

JavaScript statements can be grouped together into code blocks inside {}.

The purpose of these blocks of code is to define statements to be executed together.

We can easily see blocks of code everywhere in the JavaScript code.

For example

JavaScript Keywords

JavaScript statements are usually started with keywords. Here are some frequently used keywords in JavaScript code:

  • var: declares a variable.
  • let: declares a block scoped variable.
  • const: declares a variable as a constant.
  • if: Marks a block of statements to be executed when a condition is met.
  • switch: Marks a block of commands to be executed when a condition is satisfied.
  • for: Marks a block of statements to be executed in one round.
  • function: Declare a function.

Conclude

Through the above article, we have known some frequently used statements in JavaScript code. In the next sections, I will go into detail about each concept in JavaScript. Thank you for reading, see you in the next part.

Share the news now

Source : Viblo