a) var is confined to a particular function but let is not
b) let is confined to a particular function but var is not
c) var defines values based on conditions but let does not
d) let doesn’t let you change the value of the variable
Answer: b
Explanation: Variables declared with var have global scope whereas variable declared with let have block scope. Variables declared with let are defined only within the closest enclosing block (and any blocks nested within it, of course).
Related Posts
What would be the result or type of error if p is not defined in the following JavaScript code snippet?
console.log(p)What will be the output of the following JavaScript code if oddsums(5); is executed after the following code snippet?
function oddsums(n)
{
let total = 0, result=[];
for(let x = 1; x <= n; x++)
{
let odd = 2*x-1;
total += odd;
result.push(total);
}
return result;
}The “let” keyword cannot be used ___________
What will be the output of the following JavaScript code?
const pi=3.14;
var pi=4;
console.log(pi);What will be the output of the following JavaScript code?
set.add(“1”);
set.add(“2”);
document.writeln(set.has(“3”));What will be the output of the following JavaScript code?
set.add(“one”);
set.add(“two”);
var itr=set.values();
document.writeln(itr.next().value);What will be the output of the following JavaScript code?
set.add(“one”);
set.add(“two”);
set.add(“three”);
set.clear();
document.writeln(set.size);
Join The Discussion