I have two function they are a function declaration
function myFunction(){
console.log("3");
}
myFunction(); // prints "7"
function myFunction(){
console.log("7");
};
myFunction(); // prints "7"
I find defarent result when i make two function expression with var keyword
var myFunction = function(){
console.log("3");
}
myFunction(); // prints "3"
var myFunction = function(){
console.log("7");
};
myFunction(); // prints "7"
Some where i read about hoisting there say's js function declaration are hoisted and they gonna top of code. And js function make a object as the same name that function has.And i see that if there are 2 same name variable make with var keyword they overwrite each other. ok now when i try this
let myFunction = function(){
console.log("Old");
}
myFunction(); //Error:myFunction already declared
let myFunction = function(){
console.log("New");
};
myFunction();
so my question is there is the function declaration when run in the interputer and interputer make object as the function name who it create it with var or let