Announcement

Collapse
No announcement yet.

Odd local variable behaviour when defined in var x=y=null; format within main()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Odd local variable behaviour when defined in var x=y=null; format within main()

    I would expect both x and y to be declared as local variables but y is declared as a global variable.
    From what I've read both x and y should be local variables available only within the function they are declared in.
    If "var x,y;" format is used they are declared as local variables as expected.

    Just curious if anyone has any insight about this.

    PHP Code:
    debugClear();
    function 
    preMain(){
        
    setPriceStudy(true);
    }

    function 
    main(){
        var 
    x=y=null;
        var 
    a,b;
        
    x=1;
        
    y=2;
        
    a=3;
        
    b=4;
        
    testIt();
    }
    function 
    testIt(){
        
    //debugPrintln("13: x: "+x);//returns undefined variable error as expected
        
    debugPrintln("14: y: "+y);//returns "14: y: 2"
        //I would expect an undefined variable error for y also
        //debugPrintln("17: a: "+a);//returns undefined variable error as expected
        //debugPrintln("17: b: "+b);//returns undefined variable error as expected

    Wayne
    Last edited by waynecd; 09-13-2013, 09:37 PM.

  • #2
    Turns out that it is not odd at all, just poor syntax.

    the correct syntax is:

    //
    PHP Code:
    var x=nully=null

    Comment

    Working...
    X