Where to write javascript
Goal
- âš¡ Learn where to write javascript code
Overview
Before diving into javascript code, let's check
"where to write javascript code" in HTML file.
Where to write javascript code ?
In HTML, JavaScript code is inserted between
<script>
and</script>
tags.
https://www.w3schools.com/js/js_whereto.asp
In html file
<script>
// javascript code here...
</script>
note
<script>
tag is HTML code.- The code inside
<script>
tag is javascript code.
<script>
tag in HTML?
Where to place You can place any number of
scripts
in an HTML document.Scripts can be placed in the
<body>
, or in the<head>
section of an HTML page, or in both.
https://www.w3schools.com/js/js_whereto.asp
inside <body> tag in html file
<body>
...
<script>
// javascript code here...
</script>
</body>
or
inside <head> tag in html file
<head>
...
<script>
// javascript code here...
</script>
</head>
or both.
<html>
<head>
...
<script>
// javascript code here...
</script>
</head>
...
<body>
...
<script>
// javascript code here...
</script>
</body>
</html>