21JavaScript basics
Use of JavaScript in an HTML Document
Easy20MIN
Using JavaScript in an HTML document usually happens in two ways: by embedding the code within the HTML document or by referencing a separate JavaScript file.
Inline scripts
The first way to include JavaScript code in an HTML document is to use the <script> tag. This tag contains the JavaScript code that is executed when the HTML document is loaded. The tag is shown in the example in the head section, but it doesn't have to be exactly there. The head is loaded before the body, so if you want the script to be loaded only after the rest of the HTML has already been loaded, it is recommended to place it at the end of the body.
JAVASCRIPT
1<!DOCTYPE html><html><head><title>Using JavaScript in an HTML document</title><script>
2 alert("Hei maailma!");
3 </script></head></html>1 / 4
Hakatemia Pro
Learn to hack — start here
Hundreds of interactive courses, virtual labs and CTF challenges in your browser. Start a free trial — no card required.