First Simple JavaScript Example : Fully Explained
we have already discussed our first JavaScript example (Here). In this tutorial we are going to see different tags used in first JavaScript Example.
Basic JavaScript Example :
<!DOCTYPE html> <html> <head> <title>My first script</title> </head> <body> <script> document.write("Hello, world!"); </script> </body> </html>
Basic Tags and Attributes Explained !!!
| Tag | Attribute | Meaning |
|---|---|---|
| html | - | html Contains the HTML part of the Web page |
| head | - | Contains the header part of the Web page |
| script | - | Contains the Web page’s script or a reference to the external script file.Usually JavaScript, but not always. |
| src | The location of an external script | |
| title | - | Contains the title of the Web page |
| body | - | Contains the body part of the Web page |
Explanation :
<script>
- Opening script tag.
- Tells the browser to expect JavaScript instead of HTML.
document.write(“Hello, world!”);
- First line of JavaScript.
- It takes the document window and writes “Hello, world!” into it A.
- Note the semi-colon at the end of the line this tells the browser’s JavaScript interpreter that the line is ending.
- Semicolon is Optional
</script>
- Ends the JavaScript and tells the
- Browser to start expecting HTML again.

