moru
0
Q:

vars with let in it javascript

// var has function scope.
// let has block scope.

function func(){
  if(true){
    var A = 1;
    let B = 2;
  }
  A++; // 2 --> ok, inside function scope
  B++; // B is not defined --> not ok, outside of block scope
  return A + B; // NaN --> B is not defined
}
4
Input:
console.log(x);
var x=5;
console.log(x);
Output:
undefined
5

var and let are both used for variable declaration in javascript but the difference between them is that var is function scoped and let is block scoped.
It can be said that a variable declared with var is defined throughout the program as compared to let.
3
Input:
console.log(x);
let x=5;
console.log(x);
Output:
Error
2
let /*Var name*/ = /*what is equals*/
0

New to Communities?

Join the community