I know in JavaScript only function declarations are hoisted, which means it should print 30 after running the function sum.
However it says diff is not defined, shouldn't it be hoisted?
sum(10, 20);
diff(10, 20);
function sum(x, y) {
return x + y;
}
let diff = function(x, y) {
return x - y;
}
sumanddiffare declared at the top, thensumis defined, your calls are made, thendiffis defined (that definition is left after the calls because you usedlet). So you're calling before you define.