Javascript and weakly defined types (Part 2: Electric Boogaloo)

Javascript and its lack of strong typing continues to cause headaches.
Today's one is caused by the following bit of madness

if (true) {
    alert("true evaluates as true"); // will show

if (false) {
    alert("false evaluates as true"); // will not show

if ('true') {
    alert("'true' evaluates as true"); // will show

if ('false') {
    alert("'false' evaluates as true"); // will show

Any string that is not an empty string is treated as a true value automatically.

Be careful that any method or property that returns a true/false value returns it as a boolean value and not as a string

Share Tweet Send
You've successfully subscribed to
Great! Next, complete checkout for full access to
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.