Is there any difference in writing javascript in a single script block or in individual blocks?
Writing script in a single block
<script type="text/javascript">
function funcA(){
//do something
}
function funcB(){
//do something
}
</script>
Writing script in a different block
Block 1:
<script type="text/javascript">
function funcA(){
//do something
}
</script>
Block 2:
<script type="text/javascript">
function funcB(){
//do something
}
</script>
Multiple <SCRIPT> Tags Up to this point all of the JavaScript Code was in one <SCRIPT> tag, this does not need to be the case. You can have as many <SCRIPT></SCRIPT> tags as you would like in a document. The <SCRIPT> tags are processed as they are encountered.
Answer. Yes, you can call multiple methods, one after the other in the same statement.
External JavaScript Advantages Placing scripts in external files has some advantages: It separates HTML and code. It makes HTML and JavaScript easier to read and maintain. Cached JavaScript files can speed up page loads.
The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load. Generally, JavaScript code can go inside of the document <head> section in order to keep them contained and out of the main content of your HTML document.
Functions declared in an earlier script block can only call functions in a later script block after the page loads.
Also, if an error occurs while the first script block is executing, the second block will still run.
If you put it all in one script, any code after the error will not run at all. (except for function declarations)
All this only applies to code that runs immediately.
Code that runs later (eg, an event handler) will not be affected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With