Q
What is the difference in scope between variables declared with 'var' and 'let' in JavaScript loops?

Answer & Solution

Answer: Option B
Solution:
In JavaScript, 'var' is function-scoped, meaning it is accessible within the entire function, while 'let' is block-scoped, limiting its accessibility to the block it is defined in.
Related Questions on Average

What happens to a variable declared inside a loop with 'var' in JavaScript after the loop ends?

A). It is destroyed

B). It is still accessible

C). It becomes undefined

D). It throws an error

Can a variable declared with 'let' in a loop be accessed outside the loop in JavaScript?

A). Yes

B). No

C). Sometimes

D). Depends on the context

In PHP, what is the scope of a variable declared inside a for loop?

A). Global

B). Function-scoped

C). Block-scoped

D). Script-scoped

In JavaScript, which of the following creates a block-scoped variable within a loop?

A). var

B). let

C). const

D). Both let and const

In which scenario is a variable declared inside a loop inaccessible outside of it?

A). When using var in JavaScript

B). When using let in JavaScript

C). When using global in Python

D). When using static in C++

In Java, what happens if you declare a variable inside a for loop?

A). It becomes global

B). It is accessible only within the loop

C). It is accessible throughout the class

D). It throws an error

Which of the following keywords can be used to declare a block-scoped variable in JavaScript?

A). var

B). let

C). const

D). Both let and const

In C, what is the scope of a variable declared inside a while loop?

A). Global

B). Local to the block

C). Local to the function

D). Local to the file

In Ruby, can a variable declared inside a loop be accessed outside the loop?

A). Yes

B). No

C). Only in certain cases

D). It depends on the loop

In C++, where can a variable declared inside a for-loop be accessed?

A). Only within the loop

B). Throughout the function

C). Throughout the file

D). Outside the function