function findCount(req,res, s){
count = s.length; //count was not initialized! Causes problems.
res.send(count);
}
In Node.js, this code causes problems when there are a lot of hits, since I didn’t add “var” before count.
I’m afraid that I forget to add var to initialize my variables.
Is there a way to scan my code and determine, for each function, which variables were not initaizlied?
Better yet: Is there a way to automatically initialize all variables inside each function?
Have you used JSLint? It parses J-script for you, it’s very useful. You can find the online version here.
It would give you something like :
“Problem at line 1 character 1: ‘count’ was used before it was defined”
Hope that’s what you’re after