if ('0' == false) :
Javascript is doing something called type coercion .
Following the rules of this link, we come to rule 7:
If type (y) is boolean, return the result of the comparison x == ToNumber (y)
Calling ToNumber (false) gives us the number 0. The result now starts to make sense, but we still havenโt quite done it, because we still have a string and a number. The process starts again, and this time we come to rule 5:
If Type (x) is String and Type (y) is Number, return the result of the comparison ToNumber (x) == y: "2" == 2
This time, the left side of '0' is converted to a number: 0. Now, finally, we can compare two numbers, and since 0 is 0, the result will be true. However, it is important to note that this does not mean anything about the true / false nature of the string '0' , because it was forced before it was compared.
if('0')
In this case, there is no comparison; you only want to know if a single value is true or false. Type type applications are not used because strings can be evaluated as crazy or fake. Using the rules from the same link as before, we find the following information:
In JavaScript, not just JavaScript, we have what are called false values. This is respectively: 0, null, undefined, false, ", NaN. Please note that the empty string is empty, because otherwise than the php example," 0 "will be considered truish
The quote is especially useful because it specifically calls the string "0", but that would not be necessary. This is enough to know that an empty string is false, and any other string is true, because the contents of the string are not evaluated and no enforcement is performed. 0 can be a false value, but because we evaluate the string, and not force it to a number, and '0' has some value, it still remains true.