Javascript Statements - Types of Javascript Statements



Javascript Statements - Types of 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.
  • A JavaScript program is a list of programming statements.

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

JavaScript Statements

  • JavaScript statements are composed of Values, Operators, Expressions, Keywords, and Comments.
  • This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":

Sample Code

<!DOCTYPE html>
<html>

<body>
 <h2>JavaScript Statements</h2>
 <p>In HTML,JavaScript statements are executed by the browser.</p>
 <p id="demo"></p>
 <script>
  document.getElementById("demo").innerHTML = "Kaashiv infotech";

 </script>
</body>

</html>

Output

javascript-statements

Semicolons

  • Semicolons separate JavaScript statements.
  • Add a semicolon at the end of each executable statement:
let x, y, z;  
x = 4;        
y = 6;        
z = x + y;   

JavaScript White Space

  • JavaScript ignores multiple spaces. You can add white space to your script to make it more readable.
let company = "Kaashiv";
let name = "Infotech"; 

JavaScript Code Blocks

  • 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 myname() {
  document.getElementById("demo1").innerHTML = "welcome to ";
  document.getElementById("demo2").innerHTML = "Kaashvi infotech";
} 
Keyword Description
var Declares a variable
let Declares a block variable
const Declares a block constant
if Marks a block of statements to be executed on a condition
switch Marks a block of statements to be executed in different cases
for Marks a block of statements to be executed in a loop
function Declares a function
return Exits a function
try Implements error handling to a block of statements

Related Searches to Javascript Statements - Types of Javascript Statements