Allerious Posted April 22, 2019 Share Posted April 22, 2019 Is there any use/need/benefit from attaching window. before a global variable? In this first link it shows window.carName can be used, but removing window. from carName gives the same result, so is there ever any need for attaching window. at the beginning of global variables? https://www.w3schools.com/js/tryit.asp?filename=tryjs_let_scope This second link shows by using let instead of var for the variable creation window.carName is undefined yet it says in the green comments // code here can use window.carName. I assume that is a typing error and should read // code here can not use window.carName? https://www.w3schools.com/js/tryit.asp?filename=tryjs_let_global Link to comment Share on other sites More sharing options...
justsomeguy Posted April 22, 2019 Share Posted April 22, 2019 You only actually need to do it if you're specifically trying to refer to a global instead of a local variable, and both exist. 1 Link to comment Share on other sites More sharing options...
Funce Posted April 22, 2019 Share Posted April 22, 2019 8 hours ago, Allerious said: This second link shows by using let instead of var for the variable creation window.carName is undefined yet it says in the green comments // code here can use window.carName. I assume that is a typing error and should read // code here can not use window.carName? Good Catch! Whichever page you've got these try-its from, there's a button at the bottom of the page that says "Submit Error" which will alert the w3school staff to fix it. Just make sure you include the details you've specified here. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now