I do believe that when you specify a string for the first parameter of setInterval or setTimeout, it will be executed with eval at the specific time/interval. Because of that, it is run in the global scope. In your case, x is not available in the global scope...it's a local variable scoped inside of the testclear function. Passing a function as the first parameter to setInterval or setTimeout secures the scope you were originally working with (inside the testclear function).

Alternatively, yet not preferably, I believe you could do this:

setTimeout("clearInterval(" + x + ");",10000);

But note that this concatenation may be different or not possible in other situations (other method calls)