Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation variable declaration

    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.
    Last edited by boywonder04; 06-10-2004 at 03:34 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var a = b = c = d = new Array();
    Hope that helps!

    Happy coding!

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.

    boywonder04: no, what you want is not covered by JavaScript. You'll have to declare each of them explicitly, and make sure they are assigned a separate value instead of the same value.
    Code:
    var
        a=[],
        b=[],
        c=[],
        d=[];
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I was afraid javascript might not supoprt that. But thanks anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •