Hello World

Every programmer's journey starts with the classic Hello World program. In JavaScript you can run it right in your browser console.

Browser Console

Open your browser's developer tools (press F12 or Cmd+Option+I), go to the Console tab, and type:

console.log('Hello World!')

Press Enter — you should see Hello World! printed below.

Variables

You can store a value in a variable and then print it:

var hello = 'Hello world!'
console.log(hello)
// Hello world!

Basic Math

JavaScript can do arithmetic operations directly:

console.log(2 + 2)   // 4
console.log(10 - 3)  // 7
console.log(4 * 5)   // 20
console.log(15 / 3)  // 5
💡 Tip

The browser console is your best friend while learning JavaScript. Use it to experiment and test code instantly.

Questions

  1. What is the browser console used for?
  2. How do you print something to the console?
  3. What does var do?