Q
What is the difference between var and let in terms of scope in JavaScript?

Answer & Solution

Answer: Option c
Solution:
Variables declared with var have function scope, meaning they are scoped to the nearest function block, while variables declared with let have block scope, limited to the block they are defined in. The correct option is c. varhas block scope,let has function scope.
Related Questions on Average

What does hoisting refer to in JavaScript variable declarations?

A). a. Declaring a variable multiple times

B). b. Initializing a variable before declaring

C). c. Moving variable declarations to the top

D). d. Using undeclared variables

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

A). a. To declare variables with function scope

B). b. To declare variables with block scope

C). c. To declare constants with immutable values

D). d. To declare objects in JavaScript

What keyword is used to declare variables in JavaScript?

A). a. var

B). b. const

C). c. let

D). d. def

Which of the following variable names is valid in JavaScript?

A). a. my variable

B). b. _variable

C). c. 3variable

D). d. variable$

What is the outcome of console.log(typeof x); if x is declared but not initialized in JavaScript?

A). a. Undefined

B). b. Null

C). c. Error

D). d. Object

What does hoisting refer to in JavaScript variable declarations?

A). a. Declaring a variable multiple times

B). b. Initializing a variable before declaring

C). c. Moving variable declarations to the top

D). d. Using undeclared variables

Which of the following statements is true about the let keyword in JavaScript?

A). a. Variables declared with let have global scope

B). b. Variables declared with let are block-scoped

C). c. let is used to declare constants

D). d. let is used to declare functions

Which of the following statements is true about the let keyword in JavaScript?

A). a. Variables declared with let have global scope

B). b. Variables declared with let are block-scoped

C). c. let is used to declare constants

D). d. let is used to declare functions

What keyword is used to declare variables in JavaScript?

A). a. var

B). b. const

C). c. let

D). d. def

Which keyword is used to declare a variable that cannot be reassigned in JavaScript?

A). a. var

B). b. let

C). c. const

D). d. mutable