Register to get access to free programming courses with interactive exercises

Hello, World! JavaScript fundamentals

As usual, we'll start by writing a "Hello, World!" program. The program will print the text. To print something, you need to give computer a special command. In JavaScript, we use console.log().

Hello World

console.log('Hello, World!');
// => Hello, World!

We will sometimes show the result of running code lines using the comments, like this: => RESULT. For example, // => 4.

Comments

The source code files may contain comments in addition to the code. This is non-executable line(s) of text that is required for programmers to take notes. They're used to describe how the code works and what errors need to be fixed, as well as to remind you to add anything later.

// Delete the line below after the registration feature is implemented
console.log(10);

Comments in JavaScript are of two kinds.

Single line comments start with //. Any text or symbols that follow, won't be evaluated or executed. A comment can take up the whole line or several lines:

// For Winterfell!
// For Lanisters!

or can follow some code on the same line:

console.log('I am the King'); // For Lannisters!

Multiline comments start with /* and end with */.

/*
  The night is dark and
  full of terrors.
*/
console.log('I am the King');

Such comments usually clarify the purpose of pieces of code and build its documentation.


Recommended materials

  1. About "Hello, World!"

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

Bookmate
Health Samurai
Dualboot
ABBYY