Use of var keyword -- IE 5.2

P

PJ

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
 
L

Lasse Reichstein Nielsen

PJ said:
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;

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
 
P

PJ

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

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

Lee

PJ said:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top