Q
What is the purpose of using block scope in JavaScript?

Answer & Solution

Answer: Option B
Solution:
Block scope in JavaScript is used to prevent variable hoisting and ensure variables are only accessible within the block they are defined in.
Related Questions on Average

Which keyword is used to declare a constant array in JavaScript?

A). A. let

B). B. const

C). C. var

D). D. array

What does the const keyword signify in JavaScript?

A). A. Constant variable

B). B. Mutable variable

C). C. Global variable

D). D. Block-scoped variable

What is the primary advantage of using block scope in JavaScript?

A). A. Reducing code size

B). B. Preventing variable hoisting

C). C. Avoiding global variables

D). D. Improving performance

What is the purpose of using the const keyword in JavaScript?

A). A. To declare variables with global scope

B). B. To declare block-scoped variables

C). C. To declare variables that can be reassigned

D). D. To declare variables that cannot be reassigned

What will be the output of the code above?

A). A. 30

B). B. 31

C). C. Error

D). D. Undefined

Which of the following is NOT an example of a block in JavaScript?

A). A. Function body

B). B. if statement body

C). C. while loop body

D). D. Object literal

What is the primary difference between const and let in JavaScript?

A). A. const variables can be reassigned

B). B. let variables are block-scoped

C). C. const variables are hoisted

D). D. let variables are immutable

What happens if you try to reassign a value to a constant declared using const?

A). A. SyntaxError

B). B. TypeError

C). C. ReferenceError

D). D. No error, value is reassigned

Which of the following statements about const is true?

A). A. Variables declared with const can be reassigned

B). B. const variables have function scope

C). C. const variables cannot be used in loops

D). D. const variables are block-scoped

What will be the output of the code above?

A). A. 10

B). B. 20

C). C. Error

D). D. Undefined