I have a simple piece of Javascript code and I get this Error :
Uncaught ReferenceError: i is not defined (anonymous function)
The code is as below –
function xyz(i){
....
....
if(i==5) { // do something }
else {
i=i+1;
setTimeout("xyz(i)",10)
}
xyz(1);
Can someone please help me ? Do I need to declare ‘i’ somewhere ?
The error is in the
setTimeoutfunction. Try this, instead:Always choose an anonymous function instead of a “stringed function”