Your First JavaScript Program

Let’s write your first JavaScript program!

Here’s how you can add JavaScript to an HTML page:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello JS</title>
  </head>
  <body>
    <script>
      console.log('Hello, world!');
    </script>
  </body>
</html>

This code uses console.log() to print a message to the browser’s console.

To view the output:

  1. Right-click the page in the browser.
  2. Select InspectConsole tab.
  3. You’ll see “Hello, world!” printed.

Congratulations on running your first JavaScript program!

← PrevNext →