console.log(name) //undefined
display() /hello
var name ="shivaji";

function display(){
	console.log("hello");
}

Example _2:

console.log(name) //undefined
display() //undefined
var name ="shivaji";

var display = function(){
	console.log(" hello ");
}

Note: The anonymous function and arrow function are treated as variables, which is why it will print undefined.

var a=10;
let b=2000;
console.log(window.a) //10
console.log(window.b) //undefined //it will stored in seperate memory location

Rules :

Let: redeclaration is not possible in the same scope. It throws a syntax error, won't execute any line of code in our program

console.log("error") // not execute
var a=10;
let a=2000;

Var: redeclaration is possible in the same scope.

console.log("no error")
var a=10;
var a=2000;