''currentApple' is already defined showing in jslint
I have have some js code; in that I ran the js lint. I have this error:
'currentApple' is already defined
Do I need to remove var currentApple from else to make it work?
I'm providing my code below:
if(appleTab == Lifeline){
var currentApple = appleWorklist.getcurrentAppleTime("currentAppointmentcurrentAppleTime");
fo.allApples = currentApple;
}
else
{
var currentApple = appleWorklist.getcurrentAppleTime("CalendarcurrentAppointmentcurrentAppleTime");
fo.allApples = currentApple;
}
Solution 1:[1]
there is no blockscope in javascript, so currentApple in your code snippet is basically the same thingy.
from Douglas Crockford's bible, paragraph Variables:
JavaScript does not have block scope, so defining variables in blocks can confuse programmers who are experienced with other C family languages. Define all variables at the top of the function.
Just declare every used variable once with a var statement at the start of your function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
