πŸ“Š JavaScript
Q. What is block statement in JavaScript?
  • (A) block that combines multiple statements into a single compound statement
  • (B) both conditional block and single statement
  • (C) block that contains a single statement
  • (D) conditional block
πŸ’¬ Discuss
βœ… 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.

Explanation by: Mr. Dubey

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
236
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Kirti
Publisher
πŸ“ˆ
82%
Success Rate