JavaScript Statements

JavaScript statements are instructions to browser that are executed one by one from top to bottom. Statements are separated by semicolons. Below statement tells browser to write “Hello Reader”, inside an HTML element with id=”demo”:

document.getElementById("demo").innerHTML = "Hello Reader.";


Most of javascript programs contains more than one statements. Statements are executed one by one in the order they are written. A set of statements that perform one or more tasks is a program.


Every Javascript statement ends with semicolon (;). More than one statement can be on same line provided that each statements are end by semicolon

	a = 5;
	b = 6;
	c = a + b;
	x = 5; y = 6; z = x + y;

Download the code Run the code


Like HTML pages JavaScript also ignores multiple spaces. White Spaces are added to script to make it more readable. Below two statements are equal in JavaScript.

	var personName  = "Hege";
	var personName="Hege"; 

As a good practice all operators should have spaces around it

	var x = y + z;

JavaScript Code Blocks

A group of javascript statements are grouped together using curly brackets {…}
All statements within a code block are executed at once in the order top to bottom.
For example, Javascript functions are written within curly brackets {…} and executed sequentially on function call.

function myFunction() {
	document.getElementById("fname").innerHTML = "John";
	document.getElementById("lname").innerHTML = "Wright";

<<< JavaScript SyntaxJavaScript Output >>>
Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .