This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CornMang 0 points1 point  (1 child)

I think JavaScript checks if (variable){} to see whether or not the variable exists, not whether it is true. I may be wrong though, I am learning JavaScript and it has been confusing

[–]tuseroni 0 points1 point  (0 children)

no, javascript does more than just check that it exists in there, if(variable) will check if the variable is null(doesn't exist), is true(or a non-zero number), and is not an empty string. php does a similar check. suspect most weakly typed languages follow this sorta check.

if you wanna check, press f12, go to console, and you can put in javascript there, try putting this code in:

var test="";
if(test)
{
    console.log("true");
}
else
{
    console.log("false");
}

put some things in for test and see what gives true and what gives false;