This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 241379 - Function argument marked as unsed if used in the same line with local variable that overwrites it
Summary: Function argument marked as unsed if used in the same line with local variabl...
Status: NEW
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-04 11:59 UTC by Eccenux
Modified: 2014-02-11 16:32 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eccenux 2014-02-04 11:59:24 UTC
Example function:
```
function foobar(force) {
  var force = typeof(force)=='undefined' ? false : force;
  if (force) {
    something();
  }
}
```

Note that `force` argument is actually used two times in the function.


Workaround (in this case it might also be a better pattern):
```
function foobar(force) {
  force = typeof(force)=='undefined' ? false : force;
  if (force) {
    something();
  }
}
```
Comment 1 Petr Pisl 2014-02-05 09:25:53 UTC
From editor point of view, there is not easy to recognized, whether was used the variable or the parameter with the same name. Unfortunately the offset of the variable declaration is not important. Simple example:

function foobar3() {
    console.log(force);
    var force = "hello";
    console.log(force);
}

The local variable already exist, in the first call console.log(force), but has value "undefined", because the runtime "creates" all local variables in a function before executing the first line of the function. 

If we do this:

function foobar3(force) {
    console.log(force);
    var force = "hello";
    console.log(force);
}

it means that in the runtime the first call console.log(force) logs the local variable (not the parameter),  but the variable is initialized with the value of parameter with the same name.