In the programming language, the programming instruction is known as statements. A JavaScript program is a list of programming javascript statements.
The JavaScript statements are consists of values, operators, keywords and comments.
Example 1:
<!DOCTYPE html>
<html>
<body>
<h2> A Hello JavaScript Statements</h2>
<p>A JavaScript called list of statements to be run by a computer.</p>
<p id="darkweb"></p>
<script>
var a, b, sum; // Statement 1
a = 786; // Statement 2
b = 13; // Statement 3
sum = a + b; // Statement 4
document.getElementById("darkweb").innerHTML =
"The sum is =" + sum + ".";
</script>
</body>
</html>
Example 2:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Hello Statements</h2>
<p>Welcome to Hello JavaScript</p>
<p id="darkweb"></p>
<script>
document.getElementById("dark").innerHTML = "Hello India.";
</script>
</body>
</html>
JavaScript Line Length and Line Breaks
Most of the time the programmers don’t like or avoid codes line longer than 80 characters. The best place to break it is after an operator, if the JavaScript statement does not fit on one line.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Hello Statements</h2>
<p>
Welcome to Hello JavaScript.
</p>
<p id="darkweb"></p>
<script>
document.getElementById("darkweb").innerHTML =
"Hello India!";
</script>
</body>
</html>
Code Blocks in JavaScript
In JavaScript the statements can be groups together in a code blocks inside the curly brackets { }. It is used to define the statements to be executed together.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Hello Statements</h2>
<p>In JavaScript programming code blocks are written between { }</p>
<button type="button" onclick="myFunction()">Click Me here</button>
<p id="darkweb1"></p>
<p id="darkweb2"></p>
<script>
function myFunction() {
document.getElementById("darkweb1").innerHTML = "Hello India!";
document.getElementById("darkweb2").innerHTML = "welcome to javascript programming";
}
</script>
</body>
</html>
JavaScript Keywords
Keywords are reserved words and used for specific number of time and keywords cannot be used as a variable names.
The JavaScript Statements starts from a keywords to identify the JavaScript action that is to be performed.
There are following keywords that are used in JavaScript:
Keyword | Description |
break | To terminates a switch or a loop |
continue | To Jumps out of a loop and starts at the top |
for | To repeats the statement until the condition remain true |
do while | Repeats the statements for specific number of time |
debugger | To perform debugging process while stops the execution of block of statements |
function | Used to declare a function |
var | Used to declare a function |
return | It is used to exit a function |
Switch | Used to execute set or block of statement depending on cases |
if else | It is used to execute the statements depending upon the condition |
You can coonect us on social media apps to get more updates from us on many prograaming langaue or statements of javascript.