| Viewed 339 times

how to use javascript in html

how to use javascript in html

1 Answer
Mikdam Qandeel

Javascript in HTML pages makes them dynamic and interactive.

We can define the javascript code with <script> tag. and adding it inside the <head> section, Inside the <body> section or even after the </body> tag, it depends on, when you want to load the javascript code.


<!DOCTYPE html>

        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Today's Date</title>

            alert("Hello JavaScript!");



Try this code and reload the HTML page, it will display Hello JavaScript!.

On the other hand, we can Separate JavaScript File It's like CSS Stylesheet but we use .js extension for javascript file.

And separating the javascript file it makes the page maintenance easier and when JavaScript files are cached, pages load more quickly.



Related Questions