Difference between var and let variable

Es6 (ECMAScript 6) introduced two data types let and const for the variable declaration. var data type is a part of Es5(ECMAScript 5).
var is used for function scoped and let is used for block scoped.


example:- for(let i=0;i<10;i++){
console.log(i);
}
console.log(i); 
Output:- 0,1,2,....,9
Output:- throws an error as "i is not defined" because i is not visible

Difference between var and let variable – Objective Questions (MCQs)

Q1. var has ______ scope, while let has ______ scope.






Q2. Which variable allows redeclaration in the same scope?






Q3. Which keyword is hoisted but NOT initialized?






Q4. Which variable can cause unexpected behavior due to hoisting?






Q5. Which keyword should be preferred in modern JavaScript?