JavaScript Tutorial

JavaScript Statements

A program is a list of statements. End each one with a semicolon so the next line is not a surprise.

A program is a list

A statement is one instruction: declare a name, assign a value, call a function, or change the page. The browser runs them from top to bottom unless a later chapter changes the flow.

Put one statement on each line. End it with a semicolon. That is the house style on StudyGrid.

Example

let count = 0;
count = count + 1;
console.log(count);

Run this in /javascript/try. Open it with Try it in JavaScript. That editor.

Order matters

A name must exist before you use it. A line that logs score before score is declared will throw. Swap the lines and the same program works.

Example

let score = 10;
console.log(score);
score = 20;
console.log(score);

First the name is created. Then it is printed. Then it is changed. Then it is printed again. That sequence is the program.

Semicolons

A semicolon ends a statement. JavaScript can insert one for you at a line break. It does not always guess what you meant. Write the semicolon yourself so the next line is not glued to this one.

Example

let a = 1;
let b = 2;
console.log(a + b);

You can put more than one statement on a line if each has a semicolon. Do not. One statement per line is easier to scan and easier to debug.

A missing semicolon can make the next line part of this one. The error message often points at thenext line. Check the line above it.

White space

Spaces, tabs, and blank lines do not change meaning between tokens. Use them so a human can read the file. Indent the body of a block. Leave a blank line between groups of related statements.

let n=3; and let n = 3; do the same work. Prefer spaces around=. White space is for people. The engine ignores the extra spaces.

Blocks

Braces group statements into a block. A block is the body of an if, a loop, or a function. The statements inside still run in order. They still end with semicolons.

Example

let score = 12;
if (score >= 10) {
  console.log("pass");
  console.log(score);
}

The if line does not take a semicolon after the closing brace. The statements inside the braces do.

Expressions vs statements

An expression produces a value: 2 + 2, "hi", score. A statement does something with that value: assign it, log it, or return it. You will mix them on every line.

KindExample
Expression1 + 2
Statementlet total = 1 + 2;
Statementconsole.log(total);

Read top to bottom

Until you meet functions and events, assume every line runs once, in order, as soon as the script loads. That is enough to follow the next chapters.

Next: syntax — identifiers, literals, case, and reserved words.

FAQ: JavaScript Statements

Common questions about this page.

What is the StudyGrid JavaScript tutorial?

The StudyGrid JavaScript tutorial is a full beginner track: variables, functions, arrays, if/else, the DOM, events, storage, and fetch. Each chapter has copy-and-run examples.

Should I run javascript statements examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn javascript statements in this JavaScript JavaScript lesson (JavaScript Statements).

Is the JavaScript editor the same as Try Python?

No. Try JavaScript is a live page plus a console at /javascript/try. Try Python stays at /try. JavaScript lessons never open the Python editor.

Do I need to install anything to learn JavaScript?

No. Open a chapter, click Try it in JavaScript, and the page and console update in the browser.

Where should I start the JavaScript tutorial?

Start at JavaScript Intro, then Where To, Output, and Syntax. After variables and functions, continue to the DOM and events. Use Next at the bottom of each chapter.

Is the JavaScript tutorial free?

Yes. The JavaScript studio on StudyGrid (studygrid.in) is free: dashboard, chapters, and the live editor.