I wrote "use strict"; at the top of my script.
I can't write num = 5; because I get ReferenceError: Can't find variable: num.
To fix this I can write let num = 5;.
Using that logic, why am I allowed to write name = prompt("What is your name?");?
Shouldn't I have to write let name = prompt("What is your name?")?
Assuming that you're running this in the browser, you're seeing this behavior because of the
window.nameproperty. You're second example is storing the value returned bypromptin this property.If window had a built-in
numproperty your first example would work as well.Of course, in actual code you'd want to create a variable to store the
promptvalue rather than clobberingwindow.name.