Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Statements

JS Statements

In general, a computer program is a list of "instructions" to be "executed" by a computer and these instructions are called statements.

In HTML, JavaScript programs are executed by the web browser.

JavaScript Statements

JavaScript statements are composed of variables, values, operators, expressions, keywords, comments, etc.

These statements are executed one by one, as the same order as they are written.

The statements tells the browser what to do. For example, below statement tells the browser to write "Lynxsia IT Solutions" inside an HTML element with id="demo"

					 
        
          <!DOCTYPE html>
          <html>
            <body>
              <h1>JavaScript Statement</h1>
              <p id="demo"></p>

              <script>
                document.getElementById("demo").innerHTML = "Lynxsia IT Solutions";
              </script>
            </body>
          </html>
        
      
Semicolons

Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement:

					 
        
          var a = 10;
          var b = 10;
          var c = a + b;
          document.getElementById("demo").innerHTML = c;

          /*
            When separated by semicolons,
            multiple statements on one line are allowed
          */
          a = 5; b = 6; c = a + b;
        
      
On the web, you might see examples without semicolons. Ending statements with semicolon is not required, but highly recommended.
Whitespace

JavaScript ignores multiple spaces. You can add white space to your script to make it more readable.

A good practice is to put spaces around operators ( = + - * / ):

					 
        
          let person = "Hege";
          let person="Hege";
          let x = y + z;
        
      
Line Break

If a JavaScript statement does not fit on one line, the best place to break it is after an operator.

					 
        
          document.getElementById("demo").innerHTML =
          "Lynxsia IT Solutions";
        
      
Code Block

JavaScript statements can be grouped together in code blocks, inside curly brackets {...}.

The purpose of code blocks is to define statements to be executed together.

One place you will find statements grouped together in blocks, is in JavaScript functions.

					 
        
          function myFunction() {
            document.getElementById("demo1").innerHTML = "Hello Dolly!";
            document.getElementById("demo2").innerHTML = "How are you?";
          }
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved