Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello World program in JavaScript

In this section, we are going to install the NodeJs and write a basic program that prints "Hello World!"

Installing NodeJS

See the NodeJs setup guide here https://nodejs.org/en/download. For Windows users, you need to add NodeJs to your PATH variable — see the guide here https://hackmd.io/@hm222vx/AddNodeJSPath

Confirm NodeJs installation

When you install NodeJs, it comes with other tools like npx and npm, to confirm the installation is successfully, open a new terminal and type in the following commands, one at a time.

node -v 
npm -v
npx -v

What is an "Hello World" program ?

Put simply, it is a program that prints "Hello world" (or "Hello, world!"). It's like some sort of ritual in the broad programming community to welcome a new programmer, some sort of a baby's first cry.

Writing the Hello world program in JavaScript

Step one: Create a new hello_world.js file

touch hello_world.js

Step two: Add the code below to your hello_world.js file

console.log("Hello World!");

Step three in the same terminal used to create the new file, execute the command

node hello_world.js