• Post Reply Bookmark Topic Watch Topic
  • New Topic

Variable Example  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again, I'm still confused about variables, so I've knocked up this
HTML page to show you what I don't understand


So we can see XXX is declared in initAll(), so it is local,
but when clicking on the link... "123" is displayed in the alert.
So the function display() is using the XXX variable from the initAll()
function.
I thought this would give an error.
Can you explain why not?

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
?? Which browser are you using ?
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using netbeans 3.6 with Internet Explorer 6(I think its 6, the one that comes with XP)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you don't use var, variables are created on the window object. So once they are created inside the body of a function, they are available from that point on.

Run the following:


[ March 08, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try Colin's code, I do get a javascript error. (IE6)
Do you know why ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops sorry, I noticed that I've left onload with two 'll' (onlload)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!