Getting Started with Javascript

In this tutorial, we going to give you a brief introduction to javascript and explain some of the ways to run javascript on your computer.

Javascript is one of the most popular programming languages. It was initially developed to make our web pages interactive.  Javascript is generally used to make animations, handle form inputs, perform functions on user actions, etc.

Nowadays javascript is widely used for backend development, mobile app development, and so on.

Because of its different use cases, JavaScript can be executed in different ways.

Using browser

Using node.js

Inside web pages

Let’s discuss these all different ways of executing javascript one by one.

How to Run Javascript in Browser Console

All modern browser contains built-in javascript engines. Hence you can execute your javascript program inside your browser. To execute your javascript program follow the below steps.

1. Open any of your favorite browsers ( i m using chrome ).

2. To open developer tools, right-click on the page you are on and then click Inspect from the options. You can also use the F12 shortcut key.

3. Now from developer tools, go to the console tab. Then, write some javascript and press enter to get the output.

How to Run Javascript Using node js

Node.js is a javascript runtime environment through which you can execute your javascript code on your computer. We need Node.js to run javascript on our computer because javascript only runs in the browsers and if want to execute it in our computers like other programming languages then we need a runtime environment like node.js.

Below are the steps to execute a javascript program using node.js.

1. Install the latest version of node.js on your computer.

2. Install any IDE or code editor like Visual Studio Code. Open visual studio code, create file > write javascript code > save with .js extension.

3. Open up the terminal/command prompt > go to the location of your file > type node and then your file name ( like, node script.js ) > press enter.

4. You will get the output on the terminal.

Note: You can also execute the javascript on your terminal/command prompt. To do that, type node and then start writing your javascript code.

How to Run Javascript Inside Web Pages

Javascript was initially created to make our web pages interactive So we can run our javascript inside our HTML web page with the help of <script> tag.

Below are the steps to execute javascript inside a web page.

1. Open your VS Code > Go to File > New File > Create an HTML file and save it with .html. For example, index.html.

2. Copy the below HTML code and paste it into your index.html file and then save it.

<!doctype html>

<html>
<head>
  <title>CodingClaw</title>
</head>

<body>
  <script src=""></script>
</body>
</html>

3. Similarly create a javascript file with the .js extension and save it. For example, script.js.

4. Copy the below javascript code and paste it into your script.js file.

console.log('hello world');

5. Now we need to link our javascript file with the HTML file in order to use it. To link the javascript file add the following <script> tag inside your HTML file.

<script scr="script.js"></script>

6. Open the index.html file in your browser.

7. Now to check the output of our javascript code, Right click on the page > Inspect > Click on the console tab.

Congratulations, you learned 3 ways to execute your javascript program. I hope you enjoyed this tutorial. 

Leave a Comment

Your email address will not be published. Required fields are marked *