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:
- Right-click the page in the browser.
- Select Inspect → Console tab.
- You’ll see “Hello, world!” printed.
Congratulations on running your first JavaScript program!