I was wondering about hoisting. I know if global function name same with global variable, function overwrite variable's name. Is it right?
here is my code.
(function() {
console.log('console.log#1 ' + globalString); // globalString function
})();
var globalString = 'I\'m globalString variable';
(function() {
console.log('console.log#2 ' + globalString); // string
})();
function globalString() {
console.log('I\'m globalString function');
}
It's result show me like blow
console.log#1 function globalString ()
{
console.log ( 'I\'m globalString function' );
}
console.log#2 I'm globalString variable
If function definition overwrite variable's console.log#2 print globalString function. I don't know how variable and function hoist. please help.
console.log#1runs it's still a function. Then you overwrite it with a string value. Only declarations are hoisted, not the assignments.