Chapter 03

JavaScript Statements

A JavaScript program is made up of statements. Each statement gives the browser an instruction to execute.

What is JavaScript Statements?

  • A statement is an instruction written in JavaScript.
  • A program can contain many statements.
  • Semicolons are commonly used to mark the end of statements.
  • Statements can execute in sequence unless control-flow logic changes the execution.

Syntax

let name = 'Rahul';
let age = 20;
console.log(name);
console.log(age);

Example

Try understanding this code before running it.
let name = 'Aman';
let age = 21;
let course = 'ADCA';

console.log(name);
console.log(age);
console.log(course);

Important Points

  • JavaScript is case-sensitive.
  • Organizing statements line by line makes code easier to read.
  • Curly braces are used to create code blocks.
  • Statements should be written with correct brackets, quotes, and syntax.

Common Mistakes

  • Using spaces inside variable names.
  • Forgetting to close a string quote.
  • Using mismatched brackets or braces.

Real-World Use

JavaScript statements are used in every application to process input, perform calculations, make decisions, and update the user interface.

Practice Exercise

Practice: Statements
Store your name, age, and course in three variables and display all three values in the console.

Ready to write code?

Open the JavaScript editor and run your code with live output.

Try It Yourself →