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

Summary: Function argument marked as unsed if used in the same line with local variable that overwrites it
Product: javascript Reporter: Eccenux
Component: EditorAssignee: Petr Pisl <ppisl>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 7.4   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:

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.