Q. What is block statement in JavaScript?
β
Correct Answer: (A)
block that combines multiple statements into a single compound statement
Explanation:
A block statement (or compound statement) in JavaScript is used to group multiple statements together within curly braces {}. It is typically used in control structures like if, for, while, and function definitions.
Example of a Block Statement:
{
let a = 10;
let b = 20;
console.log(a + b); // 30
}
- The {} braces group the let declarations and console.log() into a single block.
- The block does not affect execution unless used in a specific context (like inside an if or loop).
Why Not Other Options?
- (B) Both conditional block and single statement β Incorrect. A block statement can contain multiple statements, not just a single statement.
- (C) Block that contains a single statement β Incorrect. A block is meant to group multiple statements, although it can contain just one.
- (D) Conditional block β Incorrect. A block can be used inside conditionals, but it is not limited to them.