Top.Mail.Ru
? ?
Javascript's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Sunday, January 18th, 2004

Time Event
7:41p
variable scope
It's probably obvious to most of you that the following code writes "two" to the screen:

  function changeIt() {
    number = "two";
  }
  var number = "one";
  changeIt();
  document.write(number);


And that if you declare the variable with var inside the function, it'll write "one" instead:

  function changeIt() {
    var number = "two";
  }
  var number = "one";
  changeIt();
  document.write(number);


Here's where it gets a little weird...Collapse )

<< Previous Day 2004/01/18
[Calendar]
Next Day >>
About LiveJournal.com
Image