View Full Version : variable declaration
06-10-2004, 04:24 PM
Is it possible to give multiple variables the same assignment?
mock example(doesn't really work):
var a, b, c, d = new Array();
so that a, b, c, and d are all arrays.
06-10-2004, 07:15 PM
var a = b = c = d = new Array();
Hope that helps!
Happy coding! :)
06-10-2004, 07:41 PM
nolachrymose: That doesn't quite cut it, I'm afraid. There are a number of problems with it.
1. You only declare one variable, a. The variables b, c and d go undeclared. This means that if you try to do that in a function body, the variable a will be local while the variables b, c, d will be in the global scope, given that they aren't declared in a scope in between.
2. You are not assigning each of them a new array, you are assigning them the same newly created array. This means that any change made to one of them will be reflected in all the others.
06-10-2004, 08:08 PM
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.