Q
Why is it recommended to use 'let' and 'const' over 'var' in modern JavaScript?

Answer & Solution

Answer: Option C
Solution:
It is recommended to use 'let' and 'const' over 'var' because they are block-scoped, reducing the risk of errors related to variable hoisting and scope leakage.
Related Questions on Average

What will be the result of executing 'let x = 1; let x = 2;' in the same scope?

A). x will be 1

B). x will be 2

C). Syntax Error

D). Runtime Error

What does 'TDZ' stand for in the context of JavaScript?

A). Temporary Declaration Zone

B). Temporal Dead Zone

C). Temporary Dead Zone

D). Temporal Declaration Zone

Which of the following statements is true regarding redeclaring variables in JavaScript?

A). You can redeclare 'var' variables within the same scope without errors

B). You can redeclare 'let' variables within the same scope without errors

C). You can redeclare 'const' variables within the same scope without errors

D). None of the above

What happens when you redeclare a variable with 'var' inside a function?

A). The variable is overwritten

B). The variable declaration is ignored

C). It throws an error

D). The function's scope is reset

Can you redeclare a 'var' variable in a different scope without error?

A). Yes

B). No

C). Only in strict mode

D). Only if the variable is not initialized

What error is thrown when attempting to redeclare a 'const' variable?

A). TypeError

B). ReferenceError

C). SyntaxError

D). RangeError

Which of the following statements about 'let' and 'const' is false?

A). Both 'let' and 'const' are block-scoped

B). Both 'let' and 'const' cannot be redeclared in the same scope

C). 'let' can be reassigned, 'const' cannot

D). Both 'let' and 'const' can be redeclared in different scopes

What will happen if you try to use a variable before declaring it with 'let'?

A). It will return undefined

B). It will return null

C). It will throw a ReferenceError

D). It will return NaN

Which of the following is a characteristic of 'const' variables?

A). They can be redeclared

B). They can be reassigned

C). They cannot be redeclared but can be reassigned

D). They cannot be redeclared or reassigned

Given 'var a = 1; var a = 2;', what is the value of 'a' after these statements execute?

A). 1

B). 2

C). Undefined

D). Syntax Error