Let's first see a simple example:
This is a JavaScript example
Usually, JavaScript code starts with the tag . The code placed between and . Sometimes, people embed the code in the tags:
Why do we place JavaScript code inside comment fields ? It's for ensuring that the Script is not displayed by old browsers that do not support JavaScript. This is optional, but considered good practice. The LANGUAGE attribute also is optional, but recommended. You may specify a particular version of JavaScript:
For example, shown below is the code of the external file hello.js:
document.write("Hello World!")
The external file is simply a text file containing JavaScript code with the file name extension ".js". Note:
- Including an external file only functions reliably across platforms in the version 4 browsers.
- The code can't include tags, or you will get an error message.