JavaScript fundamentals

Theory: Statements

A statement is a command given to a computer to do something. The JavaScript code is a set of statements which are usually separated by a ; symbol.

Instructions

Here is an example of some code with two statements.

console.log('Mother of Dragons.');
console.log('Dracarys!');
// => Mother of Dragons.
// => Dracarys!

Multiple statements can theoretically be placed on the same line:

console.log('Mother of Dragons.'); console.log('Drakarys!');

The output on the screen will be the same, but because the code is difficult to comprehend, the instructions are placed under each other.

Why is it important to know? A statement is a unit of execution. An interpreter, which is the program that executes code in JavaScript, needs statements to be split in this way. It reads the file with the code, splits the code into statements, and then executes them. As developers, we must be able to recognize this order and mentally split the code into independent pieces that are easy to analyze.

Recommended programs

Completed

0 / 39