TetSharing
JavaScript tutorial · 19 chapters
  1. Get started
  2. let, const and var
  3. Data types
  4. Operators and equality
  5. Strings
  6. Template literals
  7. if, else and switch
  8. Loops
  9. Functions
  10. Arrow functions
  11. Arrays
  12. map, filter, reduce
  13. Objects
  14. Destructuring and spread
  15. Classes
  16. Errors and try...catch
  17. Promises
  18. async and await
  19. JSON

Final JavaScript quiz
Cheat sheet: javascript array methods

Chapter 1 of 19 · By Ethan Cole · Updated November 21, 2026

JavaScript Tutorial for Beginners: First Program

JavaScript is the programming language built into every web browser. It makes pages interactive: menus that open, forms that check input, maps that move. The same language also runs outside the browser through Node.js, where it powers servers and command-line tools. The language is standardized as ECMAScript; the yearly editions are named ES2015, ES2016 and so on.

Your first program

console.log() writes values to the console, a text panel for developers. It is the JavaScript equivalent of Python's print(), and the first debugging tool everyone uses. Several values separated by commas are printed with a space between them.

JavaScript · editable

Expected output

Hello from JavaScript!
2 + 3 = 5
28
string number

Press Run. The code executes in a sandboxed frame inside this page, and anything sent to console.log() appears below the editor. Edit the text, add a line, and run it again.

What the example shows

  • Text values, called strings, are written in quotes.
  • 2 + 3 is evaluated before printing.
  • .length is a property of a string that holds its number of characters, spaces included.
  • typeof reports the type of a value; you will meet all the types in the data types chapter.

Statements usually end with a semicolon. JavaScript can insert missing semicolons automatically, but the rules have edge cases, so most style guides tell you to write them yourself.

Where JavaScript runs

In a web page, code lives inside a <script> element or in a separate .js file loaded with <script src="app.js"></script>. To experiment on any site, open the browser's developer tools (F12, or Cmd+Option+J in Chrome on a Mac) and type into the Console tab. With Node.js installed, save code to hello.js and run node hello.js in a terminal.

Common mistakes

  • Typing console.Log or Console.log. JavaScript is case-sensitive.
  • Using curly "smart" quotes pasted from a word processor; only straight quotes work.
  • Confusing JavaScript with Java. Despite the name, they are unrelated languages.

Summary

  • JavaScript runs in every browser and, via Node.js, on servers.
  • console.log() prints values to the console, separated by spaces.
  • Strings go in quotes; end statements with semicolons.

Quiz: Get started

1. What does console.log("a", 1 + 1) print?

The expression is evaluated first, and values are separated by a space.

2. What is the official name of the language standard behind JavaScript?

JavaScript is standardized by Ecma International as ECMAScript.

3. What does "hello".length give?

length counts the characters in the string.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.