JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Statements


📘 JavaScript Statements – The Building Blocks of JS Code

A JavaScript statement is an instruction that the browser executes. A program is essentially a series of statements.

let x = 5;
let y = 6;
let z = x + y;

Each of the lines above is a statement, and together they perform a task — adding two numbers and storing the result.


🧩 Types of JavaScript Statements

1️⃣ Declaration Statements

Used to declare variables or constants.

let name = "John";
const age = 25;

2️⃣ Assignment Statements

Used to assign values to variables.

x = 10;
y = x + 5;

3️⃣ Conditional Statements

Used to make decisions in code.

if (x > 5) {
  console.log("x is greater than 5");
}

4️⃣ Looping Statements

Used to repeat blocks of code.

for (let i = 0; i < 5; i++) {
  console.log(i);
}

5️⃣ Function Call Statements

Used to call functions.

alert("Hello!");

📝 Semicolon Usage in JavaScript

JavaScript automatically inserts semicolons in most cases. However, it's a good practice to explicitly use semicolons to avoid errors, especially in large or complex programs.

let a = 5;
let b = 10;
let sum = a + b;

📋 JavaScript Code Blocks

JavaScript code blocks are written inside curly braces {}, typically in control flow structures like if, for, and while.

if (true) {
  console.log("This is a block of code.");
}

Practice Questions

Q1. How do you declare a variable price with a value of 100 in JavaScript?

Q2. How can you write a JavaScript statement to assign the sum of two variables x and y to a third variable total?

Q3. How do you write a conditional statement that checks if a variable age is greater than 18 and logs "Adult" if true?

Q4. How do you write a loop that prints numbers from 1 to 5 using a for loop statement?

Q5. How do you write a function call statement that displays "Welcome!" using the alert() method?

Q6. How do you group two or more statements inside a code block using {} in JavaScript?

Q7. How do you create a constant variable named PI with the value 3.14?

Q8. What is the correct way to write multiple statements on separate lines with semicolons? Provide an example.

Q9. How do you write a statement that multiplies two numbers and stores the result in a variable named product?

Q10. How do you declare a variable status, assign it a string "active", and log it to the console?


JS Statements Quiz

Q1: Which of the following is a valid JavaScript statement?

A. var x;
B. int x;
C. let = 5;
D. function = start;

Q2: Which symbol is typically used to end a JavaScript statement?

A. :
B. .
C. ;
D. ,

Q3: What is the purpose of a JavaScript statement?

A. To decorate the webpage
B. To instruct the browser to perform an action
C. To link CSS files
D. To display static text

Q4: Which of the following is an example of a conditional statement?

A. const name = "Alex";
B. if (x > y) { ... }
C. for (i = 0; i < 10; i++) {}
D. x = y + z;

Q5: Which of the following keywords is used to declare a block-scoped variable?

A. var
B. const
C. let
D. Both b and c

Q6: Which of the following is not a JavaScript statement?

A. console.log("Hello");
B. document.getElementById("demo").innerHTML = "Text";
C. <p>This is a paragraph</p>
D. let score = 90;

Q7: What is the correct way to write a code block in JavaScript?

A. [...]
B. (...)
C. {...}
D. "...";

Q8: Which statement calls a function in JavaScript?

A. call function
B. alert("Hi");
C. print "Hi"
D. invoke(alert)

Q9: Which keyword is used to declare a constant in JavaScript?

A. var
B. let
C. fixed
D. const

Q10: What happens if you omit the semicolon in JavaScript?

A. The code crashes
B. The browser stops running
C. JavaScript automatically inserts it (in most cases)
D. HTML will fail to load

Go Back Top