FSM Full Stack Masterclass
Platform under construction
JavaScript course badge

JavaScript Basics

Basic

Statements

Statements are the executable instructions in JavaScript: declarations, assignments, function calls, conditions, loops, returns and errors.

const score = 82;

if (score >= 70) {
  console.log("Passed");
}

JavaScript Basics

A JavaScript program is a sequence of statements.

A statement tells JavaScript to do something. Declare a variable. Call a function. Check a condition. Repeat a block. Return a value. Throw an error.

Statements usually run from top to bottom. Control-flow statements such as if, switch, loops, return and throw can change that path.

Learning statements gives you the mental model for reading code like a timeline: what happens first, what depends on what and where the program can branch.

Declaration statement

Creates a binding, such as const total = 10.

Expression statement

Runs an expression for its effect, such as updateTotal().

Control statement

Changes flow, such as if, for, while, return or throw.

Block statement

Groups statements together between curly braces.

Examples

Good JavaScript is clear, scoped and easy to debug.

Statements in a clear order

const tasksCompleted = 18;
const minimumForRelease = 20;

if (tasksCompleted >= minimumForRelease) {
  console.log("Prepare the release.");
} else {
  console.log("Keep training core skills.");
}

Compressed flow with unclear intent

let a=18,b=20;a>=b?console.log("exam"):console.log("more");

// The code works, but the intent is harder to read for a beginner.

Rules that matter

Learn the decision before memorizing the keyword.

JavaScript becomes much easier when you understand why a pattern exists. The syntax is only the surface; the real skill is choosing the right behavior for the interface.

Read top to bottom first

Most statements execute in the order they appear.

Find the branches

if, switch, loops, return and throw can change the path.

Name intermediate values

A clear const can make a condition easier to understand.

Use blocks even when optional

Braces make grouped behavior visible.

Avoid clever compression

Short code is not automatically better code.

Keep one idea per statement

This makes debugging and review much easier.

Production thinking

JavaScript quality is visible in behavior, reliability and trust.

Why does this matter?

Statements are the motion of a program. When you can follow statements, you can understand what code actually does instead of only recognizing keywords.

Accessibility

Control-flow statements often decide which message, validation error or focus action a user receives. Bad flow can create confusing interfaces.

Production note

Production logic should be boring to read. Clear statements are easier to test, log and change safely.

SEO note

If JavaScript statements decide whether important content appears, errors in that flow can make content unavailable to visitors and crawlers.

Live code lab

Change the HTML, CSS or JavaScript and run the result.

The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.

Mini assignment

Try this now.

  • Add a third branch for scores above 90.
  • Create a const called isPassed and use it in the if statement.
  • Move the repeated output text into variables.

Practice assignment

Do this before moving to the next topic.

  1. Write a variable declaration statement.
  2. Write a function call statement.
  3. Write an if statement with an else branch.
  4. Explain the execution order out loud.

Try it yourself

Use statements to choose output

Live preview

Self-check

Before you continue, prove that you understand Statements.

Basic

Do not only read the topic. Change the code, explain what happened and answer the questions in your own words.

  1. Can you define a statement in plain language?
  2. Can you identify a declaration statement?
  3. Can you explain how if changes the execution path?
  4. Can you explain why blocks make code clearer?
  5. Can you follow the order of a small program from top to bottom?