Hello World
JavaScript is an interpreted language. Interpreted language means we just have to write the code and no need to compilation.
In HTML page we can put the our JavaScript code in between the SCRIPT tag anywhere in the page. But most of programmer put the JavaScript code in the HEAD tag as well as at the end of the body tag.
<!DOCTYPE html> <html> <head> <title>HelloWorld</title> <script> document.writeln("From Header"); </script> </head> <body> <h2>Hello World</h2> <script> document.writeln("From Body"); </script> </body> </html> //From Header //Hello World //From Body
SCRIPT tag indicates the browser that inside it executable code are there, and you have to execute it. SCRIPT tag have the type attribute. In HTML4 browser or old browser type attribute was required but in latest and HTML5 browser type attribute is not required.
<script type="text/javascript"> // JavaScript code will be come here </script>
Execution Plan:
- JavaScript statement executes only when the program execution pointer reached at the script tag.
- When all the JavaScript statement of script tag executed than pointer will go back to the HTML interpreter and execute the HTML statement.