foo();
let foo = function() {
console.log("I love Codecademy!");
};
function foo() {
console.log("I love JavaScript!");
}
In the last question of the “Hoisting in Javascript” module in Intermediate Javascript course, it claims that it will result in “SyntaxError because foo() was already declared”, but wouldn’t it be a ReferenceError if anything?
Also, to my understanding of hoisting, wouldn’t function declaration take precedence over function expressions in the scope, resulting foo() to print ‘I love Javascript!’ before running into the error? I think I’m having trouble really visualizing the order of hoisting / what it really means for let variables to be in Temporal Dead Zone (TDZ).
EDIT: jks, after an hour of research I kind of understand how it works now. I was just confused because of how javascript treats function/variable redeclarations especially in comparison between var vs. function vs. let & const.
If anyone’s having a similar question/confusion about this topic, feel free to read up on this: function - JavaScript | MDN