In this post we will learn about JavaScript Statements. A computer program is a list of “instructions” to be “executed” by a computer. In a programming language, these programming instructions are called statements. The order of execution of these Statements is the same as they are written with in the program.

1. Semicolons:

  • Semicolons separate JavaScript statements.
  • A semicolon marks the end of a statement in JavaScript.

Example:

JavaScript

let a, b, c;
a = 4;
b = 3;
c = a + b;
console.log("The value of c is " + c + ".");
Output
The value of c is 7.

Multiple statements on one line are allowed if they are separated with a semicolon.

a=4;b=3;z=a+b;

2. 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

JavaScript

function test() {
    console.log("Hello");
    console.log("How are you Smith?");
}
test()
Output
Hello
How are you Smith?

3. White Space: JavaScript ignores multiple white spaces.

Example:

JavaScript

console.log(10 * 2);
console.log(10 * 2);


Output

 20
 20

Both the result will be the same

4. Line Length and Line Breaks: JavaScript code’s preferred line length by most programmers is up to 80 characters. The best place to break a code line in JavaScript, if it doesn’t fit, is after an operator.

Example:

document.getElementById("user").inner HTML =
 "Hello World !";

5. Keywords: Keywords are reserved words and cannot be used as a variable name. A Javascript keyword tells about what kind of operation it will perform.

Some commonly used keywords are:

  • break and continue: break keyword are used to terminate a loop and continue is used to skip a particular iteration in a loop and move to the next iteration.
  • do…. while: In this, the statements written within the 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.
  • switch: This helps in executing a block of codes depending on different cases.
  • var, let, and const: These keywords are used to declare a variable in js.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, codeConfig.in Courses are your key to success. We provide top-quality content at no cost, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Explore More

How to Center a Popup Window on Screen

JavaScript window.open() method is used to open a popup window. This popup window will be placed in the center of the screen. This example creates the pop-up window without placing it into

How to hide URL in the popup window opened using window.open

If you are using below code to open a popup window in your web page, then address must be appearing in you pop up window and f you want to

window.showModalDialog is deprecated in Edge and Chrome

If you have a website being compatible with Edge/Chrome and in past it was only compatible with IE 11 and if you are using window.showModalDailog in your JavaScript code, then