The programming instructions written in a program in a programming language are known as statements.
Order of execution of Statements is the same as they are written.
- Semicolons:
- Semicolons separate JavaScript statements.
- Semicolon marks the end of a statement in javascript.
Example:
<!DOCTYPE html><html><body><h2>Welcome</h2><pid="geek"></p><script>// Statement 1var a, b, c;// Statement 2a = 2;// Statement 3b = 3;// Statement 4c = a + b;document.getElementById("geek").innerHTML ="The value of c is " + c + ".";</script></body></html>chevron_rightfilter_noneOutput:
- Multiple statements on one line are allowed if they are separated with a semicolon.
a=2;b=3;z=a+b;
- Code Blocks:
JavaScript statements can be grouped together inside curly brackets. Such groups are known as code blocks. The purpose of grouping is to define statements to be executed together.Example:JavaScript function
<!DOCTYPE html><html><body><p>Welcome</p><buttontype="button"onclick="myFunction()">Click Me!</button><pid="geek1"></p><pid="geek2"></p><script>function myFunction() {document.getElementById("geek1").innerHTML = "Hello";document.getElementById("geek2").innerHTML ="How are you?";}</script></body></html>chevron_rightfilter_noneOutput:
Before Click:

After Click:
- White Space:
- Javascript ignores multiple white spaces.
Javascript would treat following 2 statements as same:
Example:var a="Hello Geek"; var a = "Hello Geek";
- Line Length and Line Breaks:
Javascript code preferred line length by most programmers is upto 80 characters.
The best place to break a code line in Javascript, if it doesn’t fits, is after an operator.
Example:document.getElementById("geek1").innerHTML = "Hello Geek!"; - Keywords:
Keywords are reserved words and cannot be used as variable name.
A Javascript keyword tells about what kind of operation it will perform.Some commonly used keywords are:
- break: This is used to terminate a loop or switch.
- continue: This is used to skip a particular iteration in a loop and move to next iteration.
- do…. while: In this the statements written within do block are executed till the condition in while is true.
- for: It helps in executing a block of statements till the condition is true.
- function: This keyword is used to declare a function.
- return: This keyword is used to exit a function.
- var: This keyword is used to declare a variable.
- switch: This helps in executing a block of codes depending on different cases.
Recommended Posts:
- Difference between try-catch and if-else statements in PHP
- What is the use of curly brackets in the `var { ... } = …` statements ?
- Break and Next statements in R
- CoffeeScript | Statements
- What is the use of number after “break” or “continue” statements in PHP ?
- How to use if statements in Underscore.js templates ?
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | What is JavaScript ?
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


