...

View Full Version : Variable assignment question.



Scriptdaemon
12-17-2006, 05:28 AM
All I really need is confirmation for this, but is this:

var variable1 = variable2 = variable3 = value;

The same as and just as legal as this?

var variable1 = value;
var variable2 = value;
var variable3 = value;

koyama
12-17-2006, 06:25 AM
Legal? Yes, I think. But it is not the same. What you get is equivalent to


var variable1 = value;
variable2 = value;
variable3 = value;
Variables don't have the same scope.

Scriptdaemon
12-17-2006, 02:20 PM
Legal? Yes, I think. But it is not the same. What you get is equivalent to


var variable1 = value;
variable2 = value;
variable3 = value;
Variables don't have the same scope.

But that ^ would return a warning saying the two latter ones were assigned a value without being declared, wouldn't it?

I don't get that error with var = var1 = var2 = var3 = value;.

ess
12-17-2006, 04:15 PM
In most cases, you don't have to declare a variable in JavaScript using the var keyword.

However, it is recommended that you do declare them using the var keyword.

Also, you can declare variables in the following manner:



var varaible1 = "Something",
variable2 = "Something",
variable3 = "Something",
variable4 = "Something";


Good luck.
Ess



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum