Use of var keyword -- IE 5.2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PJ

    Use of var keyword -- IE 5.2

    Can someone tell me why this works on IE Mac:

    uniqueId = (new Date()).getTime () % 10000000;

    but this doesn't????

    var uniqueId = (new Date()).getTime () % 10000000;

    Other instances of the var keyword do not have issues? What gives? TIA~ PJ


  • Lasse Reichstein Nielsen

    #2
    Re: Use of var keyword -- IE 5.2

    "PJ" <you@wish.com > writes:
    [color=blue]
    > Can someone tell me why this works on IE Mac:
    >
    > uniqueId = (new Date()).getTime () % 10000000;
    >
    > but this doesn't????
    >
    > var uniqueId = (new Date()).getTime () % 10000000;[/color]

    Not without seeing the rest of the code.

    I *guess* that you refer to a variable called "uniqueId" outside the
    scope of this local variable declaration.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • PJ

      #3
      Re: Use of var keyword -- IE 5.2

      [color=blue]
      > I *guess* that you refer to a variable called "uniqueId" outside the
      > scope of this local variable declaration.[/color]

      That was my first thought, but a change in the variable name does not fix
      the issue.


      Comment

      • Lee

        #4
        Re: Use of var keyword -- IE 5.2

        PJ said:[color=blue]
        >
        >Can someone tell me why this works on IE Mac:
        >
        >uniqueId = (new Date()).getTime () % 10000000;
        >
        >but this doesn't????
        >
        >var uniqueId = (new Date()).getTime () % 10000000;
        >
        >Other instances of the var keyword do not have issues? What gives? TIA~ PJ[/color]

        What do you mean by "works".

        If you put the line:

        alert(uniqueId) ;

        after both of those, you'll see that they both assign values.
        Maybe you don't realize that the "var" keyword makes the variable
        local to the function in which it is declared, which means that
        it won't be available elsewhere.

        The alerts may also show you that, despite being measured in
        milliseconds, the clock that drives Date() isn't really updated
        that often.

        Comment

        Working...