Opened 15 years ago

Closed 15 years ago

#3057 closed defect (duplicate)

using VAR for same variable name within if..then..else clause produces incorrect results

Reported by: guest Owned by: alex
Priority: high Milestone:
Component: General Version: 0.9
Keywords: Cc:
Blocked By: Blocking:


I had code similar to the following:

if (subvalues[1] != undefined) {

var tmpreport=subvalues[1];

} else { var tmpreport="another value"; }

after applying shrinksafe, each reference to var tmpreport was created as a different variable.

Something like:

if (_1ca != undefined) {

var _1cd=_1ca;

} else { var _1ce="another value"; }

Since they were both VAR tmpreport, I'd expect them to both be VAR _1cd

Change History (4)

comment:1 Changed 15 years ago by sjmiles

Owner: changed from anonymous to alex

Fwiw, using "using VAR for same variable name" inside a single function is not necessary and generally considered bad form.

I'll let Alex decide if this is 'wontfix' or 'fix', but you can solve your immediate problem by simply removing the extra 'var'. Javascript detects var declarations exclusive of any execution path.

I.e. if (false){var x=3;} will declare 'x' (but does not assign 3 to it).

comment:2 Changed 15 years ago by sjmiles

Priority: highnormal
severity: majorminor

comment:3 Changed 15 years ago by guest

duplicate: This behavior is already described in ticket #2876

comment:4 Changed 15 years ago by sjmiles

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.