Jump to content

what is the purpose of window.


Allerious

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...