JavaScript for Beginners - Creating Your First JavaScript (P: II)

Your First JavaScript

JavaScript lives inside the HTML document. Below is a sample HTML document with <head> and <body> tags, in which we will write our JavaScript code
In HTML JavaScript code must be inserted between <script> and </script> tags:
JavaScript can be placed in the HTML page’s <body> and <head> sections. In the example I Placed it within the <body> tag.

Let’s use JavaScript to print “Hello Sri Lanka” to the browser

The document.write() function writes a string into out HTML document. This function can be used to write text, HTML or both.
Output
Note: It is a good idea to place scripts at the bottom of the <body> element. This can improve page load, because HTML display is not blocked by scripts loading 


Comments