Jump to content

what is the purpose of window.


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...