This snippet results in a JavaScript runtime error: (foo
is not defined)
if (foo) {
// ...
}
I have to define foo
You'll have to define it, to be able to check it for a value. In this case you're checking weather it's true. This variable is obviously not set to anything at all, same as null in C# and Nothing in VB for example.
If you must, debugging issues or whatever, you could check if the variable is undefined like this:
if (typeof(variable) == "undefined")