JavaScript Statements

JavaScript Statements


var a, b, c;    // Statement 1
a = 5;          // Statement 2
b = 4;          // Statement 3
c = a + b;      // Statement 4

JavaScript Programs

The idea of the statement is the same in every programming language.
A computer program is a list of ‘ instructions’ to be ‘executed’ by a computer.
Computers follow these ‘ instructions ‘ or ‘ steps’.
Computers read these instructions from top to bottom, one by one.
It’s like doing something step by step.

But in a programming language, these programming instructions are called statements.

Javascript Statements end with a Semicolons ;

The idea of ‘statement’ is the same in every programming language.
But each programming language has its own syntax.
The syntax is a set of rules you have to follow when you write a computer program.
In Javascript, every statement ends with a semicolon ( ; ).
Semicolons separate JavaScript statements.
Like so:

var x, y, z;     // Create or Declare 3 variables
x = 10;         // Assign the value 10 to x
y = 5;          // Assign the value 5 to y
z = x + y;     // Assign the sum of x and y to z

JavaScript White Space

For computers, it doesn’t matter if you put codes side by side they can read them.
But for us humans, it will be hard to read. Thus we use white space.
JavaScript ignores multiple spaces. You can add white space to your script to make it more readable.
The following codes are equivalent.

var name = "Lia Sue";  //  good practice
var name="Lia Sue";

İt’s a good practice to put spaces around each operator ( = + – * / )

Comments are closed.