Variable Scope Syndrome is a condition where a programmer is unable to tell where a variable is declared, used, or modified. Symptoms include:
- Confusion about variable accessibility across functions
- Difficulty in understanding variable persistence between scopes
- Unexplained changes to global variables
The most common cause of Variable Scope Syndrome is poor naming conventions and lack of documentation.
Here's an example of the disease in action:
var myVar = 10;
function doSomething() {
var myVar = 20;
return myVar;
}
console.log(myVar); // outputs 10, but should output 20
To cure Variable Scope Syndrome, use block-level scope with let or const instead of var.