let num = 50;
const logNum = () => {
num = 100; // Take note of this line of code
console.log(num);
}
logNum(); // Prints 100
console.log(num); // Prints 100
This is an example from a codecademy lesson on scope. I thought that num would only be 100 inside of the function body (local) and that outside of the function body (global) it would remain 50? Can someone explain what is happening?
I have asked ChatGPT about this and it said that the example is incorrect however I am not sure because each codecademy lesson is made by several people with extreme thought and effort put into the lesson and I would be surprised if it was actually wrong.