Skip to main content

First Javascript Program


Getting Started With Javascript: First Javascript Program

When you're new to JavaScript, the first step is often the hardest. To help make it easier, we're going to guide you through creating your very first JavaScript program.

What is JavaScript?

JavaScript is a high-level, interpreted programming language that is mainly used to create interactive effects within web browsers. It's one of the three primary technologies of the World Wide Web, alongside HTML and CSS.

Setting up the Environment

Before we start coding, we need to set up our environment. For this tutorial, all you need is a modern web browser and a text editor. For browsers, we recommend Chrome, Firefox, Safari or Edge. For text editors, you can use Notepad, Sublime Text, Visual Studio Code, Atom, or any other text editor of your choice.

Your First JavaScript Program

To begin, open your text editor and let's create a new HTML file. You can name it index.html. HTML is the standard markup language for creating web pages.

In your index.html file, add the following code:

<!DOCTYPE html>
<html>
<head>
<title>My First JavaScript Program</title>
</head>
<body>
<script>
// Your JavaScript code will go here
</script>
</body>
</html>

In this HTML file, we've added a script tag inside the body tag. This is where we'll put our JavaScript code.

Now, let's write some JavaScript code. Replace // Your JavaScript code will go here with the following JavaScript code:

alert('Hello, World!');

Save your changes and open the index.html file in your web browser. You should see a pop-up alert with the message "Hello, World!".

Congratulations! You've just written your first JavaScript program.

Explaining the Code

The alert() function is a part of JavaScript's window object. The window object represents the browser's window. In our code, alert('Hello, World!'); is a JavaScript command that creates a pop-up alert in your web browser with the text 'Hello, World!'.

Wrapping Up

In this tutorial, we walked you through creating your first JavaScript program, which displayed a simple 'Hello, World!' message. This is a small step, but it's a big leap in your JavaScript learning journey. Don't stop here. Keep practicing and experimenting with different JavaScript functions and commands. The more you practice, the more confident and comfortable you'll become with JavaScript. Happy coding!