Q
What is the benefit of using const over var in JavaScript?

Answer & Solution

Answer: Option C
Solution:
Using const over var in JavaScript helps prevent accidental reassignments of variables, improving code reliability and reducing the risk of unintended changes to variable values.
Related Questions on Average

What will happen when you try to execute this code?

A). 14 will be logged to the console

B). 14159 will be logged to the console

C). SyntaxError will occur

D). TypeError will occur

What will be the output of the code above?

A). 10

B). 20

C). Error

D). Undefined

Which of the following statements about const is true?

A). Variables declared with const can be reassigned

B). const variables have function scope

C). const variables cannot be used in loops

D). const variables are block-scoped

What will be logged to the console after executing the code above?

A). ['red', 'blue', 'green', 'yellow']

B). ['red', 'blue', 'green']

C). ['yellow']

D). Error

Which statement about JavaScript's const is true?

A). const variables can be redeclared

B). const variables are globally scoped

C). const variables are mutable

D). const variables cannot be reassigned

In JavaScript, const variables are not hoiste What does this mean?

A). They are hoisted to the top of the block

B). They cannot be used before declaration

C). They are accessible in nested scopes

D). They are block-scoped variables

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

A). SyntaxError

B). TypeError

C). ReferenceError

D). No error, value is reassigned

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

A). Function body

B). if statement body

C). while loop body

D). Object literal

What will be the output of the code above?

A). 30

B). 31

C). TypeError

D). Undefined

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

A). Reducing code size

B). Preventing variable hoisting

C). Avoiding global variables

D). Improving performance