JavaScript Tutorial - Hello World

  1. JavaScript Hello World
  2. Basic JavaScript Syntax Rules

In this tutorial, we’re going to do a simple Hello World program in JavaScript as the starting point of our JavaScript tutorial.

JavaScript Hello World

<!DOCTYPE HTML>
<html>

<body>

  <p>JavaScript Tutorial</p>

  <script>
    alert( 'Hello, world!' );
  </script>

</body>

</html>
<script>
	alert( 'Hello, world!' );
</script>

When we embed JavaScript in a web page, we always have to embed it within the script tags <script>...</script>.

alert( 'Hello, world!' );

It is simply an alert with information Hello World! within the parenthesis, and then it ends with a semicolon.

If you save the above code to a file named like helloworld.html and then view it in a browser, you will get a pop-up box saying Hello world!.

Basic JavaScript Syntax Rules

Before we continue to learn JavaScript further, we should get some basic syntax rules of this scripting language.

  • JavaScript is case sensitive. It is valid for both variables and functions.
  • Each statement ends with a semicolon.
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.