JavaScript is a client-side scripting language. Javascript code is downloaded from the server and executed on client’s browser.
We can include javascript statements in html file or we can create a javascript file and can import it on html files.
In html file we can use script
tag to write javascript statements.
Syntax
1 2 3 | <script type="text/javascript"> javascript statements </script> |
we can write script tags inside the head or inside the body section.
Example
1 2 3 | <script type="text/javascript"> document.write("Hello Friends"); </script> |
Result
1 | Hrllo Friends |
We can also put script
tag inside body generally we include as last statement of body
Java Script Tutorial
1 2 3 | <script type="text/javascript"> document.write("Hello Friends"); </script> |
Result
1 | Hrllo Friends |
Here document refers to body of browser and write() is a function used to write the content on browser body.
We can create a separate javascript file and can include that file in html
We have a javascript file names myJavaScript.js
1 2 3 | <script type="text/javascript"> document.write("Hello Friends"); </script> |
Same folder having file first.html
1 2 3 4 5 6 7 8 | <html> </head> <script type="text/javascript" src="myJavaScript.js"> </head> <body> <h1>Java Script Tutorial</h1> </body> </html> |