Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 156 ยท Getting Started

What Is JavaScript?

Find out what JavaScript is, what it does in the browser and beyond, write your first program and learn how the live console editors in this course work.

Welcome to the JavaScript course! If HTML is the structure of a web page and CSS is its look, JavaScript is its behavior. It is the language that makes a menu open when you tap it, checks a form before it is sent, updates a price when you change the quantity, and loads new messages without reloading the page.

JavaScript is also the only programming language that runs natively in every web browser. That makes it one of the most widely used languages in the world, and a wonderful first language: all you need to start is a browser, and you can see your code working in seconds.

You don't need any programming experience for this course. We start from zero, explain every new idea, and give you a live editor in every lesson so you can experiment as you read. Knowing a little HTML helps for the later chapters about web pages; the HTML course covers it if you want a refresher.

What JavaScript does

A programming language lets you give a computer step-by-step instructions. JavaScript instructions can do things like:

  • Calculate and decide: add up a shopping cart, check whether a password is long enough, pick a random tip of the day.
  • React to people: run code when someone clicks a button, types in a field or scrolls the page.
  • Change the page: add, remove or edit text, images and styles while the page is open.
  • Talk to servers: fetch fresh data, such as weather or search results, and show it without a full reload.
  • Remember things: store settings in the browser so they are still there tomorrow.

A web page works fine without JavaScript. It just can't do much on its own after it loads. JavaScript is what turns a document into an application.

HTML, CSS and JavaScript together

The three languages of the web each have one job:

Language Job Example
HTML Structure and meaning "This is a button labeled Add to cart."
CSS Presentation "Buttons are green with rounded corners."
JavaScript Behavior "When the button is clicked, add the item and update the total."

You will see all three working together in the DOM chapter. Until then, we focus on the JavaScript language itself, because that knowledge applies everywhere JavaScript runs.

Not only in the browser

JavaScript started in the browser in 1995, but today it runs in many other places. Node.js and similar runtimes run it on servers and on your own computer, so the same language powers websites, command-line tools and back-end APIs. It also runs inside desktop apps, mobile apps, browser extensions and even some databases. The next lesson, Where JavaScript Runs, takes a closer look.

JavaScript is not Java. The similar name was a marketing decision in the 1990s. The two languages are unrelated and work very differently. The official standard behind JavaScript is called ECMAScript, and a new edition is published every year, so you will sometimes see names like "ES2015" or "ES2024" for features added in a given year.

One language, several programming styles

JavaScript doesn't force one way of organizing code. It is a multi-paradigm language, so you can pick the style that fits the problem, and mix styles in the same program:

  • Imperative (procedural): a list of steps that change variables, with loops and if statements. Great for small scripts.
  • Object-oriented: data and the functions that work on it live together in objects and classes. JavaScript objects can inherit directly from other objects through prototypes, and class syntax sits on top of that.
  • Functional: small functions without side effects, passed around as values and combined with map, filter and reduce.
  • Event-driven and asynchronous: you describe what should happen when a click, a timer or a network reply arrives. This is how browsers and servers stay responsive.

The next editor solves the same small task, summing the prices of the items that are in stock, in three styles.

JS Three styles, one task

Press Run (or Ctrl + Enter) to see the console output here.

No output.

You'll meet all of these styles later: functional programming, classes and asynchronous code.

Your first program

Tradition says your first program should greet the world. In JavaScript, you print a message with console.log(). Press Run (or Ctrl + Enter, Cmd + Enter on a Mac) and watch the output panel.

JS Hello, world

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Three lines of code, three lines of output. Here is what is happening:

  • console.log(...) prints whatever you put between the parentheses.
  • Text in quotes, like "Hello, world!", is a string. It is printed exactly as written.
  • 2 + 3 is not in quotes, so JavaScript calculates it first and prints 5.
  • Each line ends with a semicolon ;, which marks the end of an instruction.

Now change the messages, add a fourth line, or try console.log(7 * 6). You cannot break anything: the Reset button always brings back the original example.

How the editors in this course work

Almost every lesson contains live editors like the one above. There are two kinds, and it's worth knowing how they behave.

Console editors

Most lessons in the first chapters use a console editor, marked with a small JS badge. You write code on one side, press Run, and the output appears in the console panel next to it (or below it on narrow screens). It behaves much like the console in your browser's developer tools or in Node.js:

  • Run (or Ctrl + Enter) runs all of the code from the top. Nothing runs until you ask.
  • Reset restores the original example and clears the output.
  • Every run starts fresh. Variables from a previous run are forgotten, so each run is a clean experiment.
  • Only what you log is shown. Unlike typing into a browser console, the editor does not print the value of each line automatically. If you want to see something, wrap it in console.log().
  • Values are shown like a real console. Arrays, objects and other structures are printed in a readable form, and text inside them is shown in quotes.
  • Errors are reported with a line number from the editor, so you can find the problem quickly.
  • Tab indents your code. To move keyboard focus out of the editor, press Escape and then Tab.

Try the next example. It logs a few different kinds of values, then makes a deliberate mistake on line 8.

JS Values, structures and an error

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The output shows each value in its own style, then an error in red: consol is not defined, on line 8. Notice that the code after the error never ran. When JavaScript hits an error it can't handle, it stops. Fix the typo and run again, and all lines appear. Reading error messages calmly is a real skill; you will practice it in The Console and First Debugging Steps.

The editors run your code in an isolated sandbox. That keeps the course site safe, but it also means a few browser features, such as saved storage and cookies, are not available there. Lessons that need them say so and show a workaround.

Page editors

Lessons about web pages use page editors instead. You write HTML, CSS and JavaScript together, a live preview of the page appears, and anything you log shows up in a console strip underneath. Page editors re-run automatically shortly after you stop typing (untick Live to turn that off).

A page with a little behavior

Don't worry about understanding every line yet. By the end of the DOM chapter you will write code like this from memory.

A quick taste of the language

Here is a slightly bigger program, just to show where you are heading. It stores some data, uses a function to do a calculation, and prints the results.

JS A small shopping cart

Press Run (or Ctrl + Enter) to see the console output here.

No output.

You will learn every piece of this: variables (const, let), arrays and objects, functions, loops and number formatting. Try changing a quantity and running it again.

What you will learn

The course is organized into chapters that build on each other:

  1. Getting Started: running code, syntax, variables and the console.
  2. Data Types and Operators: numbers, strings, booleans, null and undefined, comparisons and logic.
  3. Control Flow: making decisions with if and switch, and repeating work with loops.
  4. Functions, Objects and Arrays: the building blocks of every real program, including modern tools like destructuring, spread and map/filter/reduce.
  5. Classes, Errors and Debugging: organizing larger programs and fixing them when they break.
  6. Asynchronous JavaScript: timers, promises, async/await and fetching data.
  7. Modules, the DOM and Browser APIs: splitting code into files and building interactive pages.
  8. Built-in Tools: dates, number and date formatting, regular expressions, iterators and more.

The course ends with four projects: a to-do app, a quiz game, a weather dashboard and an expense tracker. Each one combines what you have learned into something complete you can be proud of.

How to get the most out of this course

  • Run every example, then change it. Predict the output before you press Run. When you are wrong, that is exactly where the learning happens.
  • Break things on purpose. Remove a quote or misspell a name and read the error message. You will meet those messages again, so it helps to recognize them.
  • Take the quiz at the end of each lesson. It takes a minute and shows what to review.
  • Go in order, at least through the first few chapters. Later lessons assume you know the earlier ones.
  • Type code yourself rather than copying it. Your fingers learn the syntax faster than your eyes.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which job belongs to JavaScript on a web page?

    HTML gives structure and meaning, CSS handles presentation, and JavaScript adds behavior, such as reacting to input and changing the page.
  2. 2. What does console.log(2 + 3); print?

    2 + 3 is not in quotes, so JavaScript calculates it first and logs the result, 5.
  3. 3. In a console editor, you write 10 * 4 on a line by itself and press Run. What appears in the output?

    The console editor only shows what you log. The expression is calculated, but nothing prints it. Use console.log(10 * 4) to see 40.
  4. 4. Your code has an error on line 3 of 6. What happens when you run it?

    JavaScript runs the code from the top and stops at an error it can't handle, so lines after the error don't run. (A typo that breaks the grammar of the code is different; you will meet syntax errors soon.)
  5. 5. How are JavaScript and Java related?

    The similar name was a 1990s marketing choice. The languages were designed separately and work very differently.

Summary

  • JavaScript adds behavior to web pages and is the only language that runs natively in every browser. It also runs on servers and computers through runtimes such as Node.js.
  • HTML is structure, CSS is presentation, JavaScript is behavior.
  • console.log() prints values. Text in quotes is a string; expressions like 2 + 3 are calculated first.
  • Console editors run your code when you press Run or Ctrl + Enter, start fresh every time, only show what you log, and report errors with line numbers. Reset restores the example.
  • Page editors show a live preview of a web page plus its console output.
  • The standard behind JavaScript is ECMAScript, updated every year.

Next: Where JavaScript Runs โ€” the browser console, script tags, files and Node.js.