i am learning javascript and want to use synchronous javascript call in my code.
For example i have two scripts, script1.js and script2.js. Here is script1.js:
<script>
var value1="Script 1";
alert(value1);
//calling script2
url="script2.js"
document.write("<scr" + "ipt src=\"" + url + "\"></scr" + "ipt>");
</script>
Here is script2.js
<script>
var value2="Script 2";
</script>
Now my question is can i print value from script2 like if i add this( alert(value2);) in my script1.js.
<script>
var value1="Script 1";
alert(value1);
//calling script2
url="script2.js"
document.write("<scr" + "ipt src=\"" + url + "\"></scr" + "ipt>");
alert(value2);
</script>
I have done this using asychronous js as
var scr = document.createElement('script');
scr.setAttribute('src', url);
var head = document.getElementsByTagName("head")[0];
head.appendChild(scr);
It is working but i want to achieve this synchronously any suggestions??
Thanks in advance