Execution in Javascript

Something Like that:
Execution

For that you need to create first html code.

HTML

<p>Value of b = <span id="demo1"></span></p>
<p>Value of a = <span id="demo2"></span></p>
<p>Value of a = <span id="demo3"></span></p>

After that add this JS code.

JS

//The Execution Content
function b(){
 document.getElementById("demo1").innerHTML = "Called b!";
}
b();
document.getElementById("demo2").innerHTML = a;
var a = 'hello';
document.getElementById("demo3").innerHTML = a;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”QMyOEY” default_tab=”result” user=”pradeepanvi”]See the Pen Execution in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

Value of B = Called b!
Value of A = undefined
Value of A = hello

There you can see B is function and this is calling well.
But A is undefined and after that it is showing value “hello”

This is strange because you can see before one when a is calling, But value didn’t defined.

JS

//The Execution Content
function b(){
 document.getElementById("demo1").innerHTML = "Called b!";
}
b();
document.getElementById("demo2").innerHTML = a;
var a = 'hello';
document.getElementById("demo3").innerHTML = a;

But when value is defined! it is showing value.

JS

//The Execution Content
function b(){
 document.getElementById("demo1").innerHTML = "Called b!";
}
b();
document.getElementById("demo2").innerHTML = a;
var a = 'hello';
document.getElementById("demo3").innerHTML = a;

This Execution is only for value because if I changed function calling method. It will be work as well.

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”gxPvvm” default_tab=”result” user=”pradeepanvi”]See the Pen Execution in Javascript 02 by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see I changed the sequence of calling b, now it is before function.

Value of B = Called b!
Value of A = undefined
Value of A = hello

But still now B is fine.

Leave a Reply

Your email address will not be published. Required fields are marked *