7/04/2018

Statement Execution in JavaScript

Statement Execution in JavaScript. Let’s now study about JavaScript Statement execution. Statements are Instruction in a computer program and instruction execute by computer. In this tutorials, we also talk about the  JavaScript Statement execution these instruction called statements which are written in programming language IE. C, C++(C Plus Plus or CPP), and Java, Javascript, and any other programming language. A JavaScript program is a list of Instruction or programming statements, many Instruction or programming statements. Many exist in single javascript program.

We all know that for executing this javascript instruction we have different-different IDE(Integrated Development Environment) or editor or compiler but in javascript, these instruction or statement are executed by the web browsers ie. Google Chrome, Mozilla Firefox, Safari, Internet Explorer. Google Chrome is most recommended nowadays. Most JavaScript programs contain many JavaScript statements or instructions and these statements or instructions are executed, one by one, in the same order as they are written. Javascript statements(are often called JavaScript code) or instructions are very simple cause they follow a similar rule as a programming language follow.

JavaScript Statement execution explain

1) When Browser is trying to execute the JavaScript code, then browser understands that every statement is a command.

<!DOCTYPE html>
<html>
<body>
<p>JavaScript statements<p>
<p id="new"></p>
<script>
document.getElementById("new").innerHTML = " every statement is a command ";
</script></body>
</html>

2) Many statements are allowed in one line and statements are separated by a semicolon.

<!DOCTYPE html>
<html>
<body>
<p>Many statements </p>
<p id="MultistatementDemo"></p>
<script>
var i, j, k;
i = 5; j = 9; k = i + j;
document.getElementById("MultistatementDemo").innerHTML = k;
</script>
</body>
</html>

3) Javascript statements are always executed in sequence, means line by line rule followed by the browser when javascript statements run.

<!DOCTYPE html>
<html>
<body>
 <b>Sequence Execution of Statements</p>
<p id="abc"></p>
<script>
var a, b, c;  // Statement 1
a = 1;        // Statement 2
b = 2;        // Statement 3
c = a + b;    // Statement 4

document.getElementById("abc").innerHTML ="Here c is " + c + ".";
</script>
</body>
</html>

4) If javascript code statement is going long, you can break it in multiple lines, It is treated as a single line in JavaScript, But to make the code readable the best practice is to break the line after a comma or after some operator.

Recommendation: Always try to break a long code in lines, its easy to handle and it can save a lot of time, cause mouse doesn't have any verticle scroll option.

<!DOCTYPE html>
<html>
<body>
<p id="place"></p><script>
document.getElementById("place").innerHTML =
"Hello JavaScript!";

//this will also works
//document.getElementById("place").
//innerHTML =
//"Hello JavaScript!";

</script>
</body>
</html>

Last Words


If you have any doubt and need any help feel free to contact us or you can comment below, we are responsible to reply within 24 hours and you can like our Facebook page or Facebook group for any personal assistant. We are committed to helping student first so don't hesitate to ask any doubts and query. Join us and become the part of our organization.

Please share this article to help a newbie student or programmers.

Author Bio:


JavaScript Statement execution in JavaScript Tutorials is provided by Suman Yadav. Thanks, Suman for the Awesome and Unique article. If you want to submit your article and want to be a member of our ProgrammingWithBasics Family Join us by sending a well-written article more information read Write for Us

No comments:

Post a Comment