In JavaScript when verifying true condition
Below
if(variablename=='true')
is working but
if(variablename==true)
is not working. Any reasons for this? Is it specific to some browsers?
In JavaScript when verifying true condition
Below
if(variablename=='true')
is working but
if(variablename==true)
is not working. Any reasons for this? Is it specific to some browsers?
Strings and booleans aren't the same thing at all. Non-empty strings are all equivalent to true (How can I convert a string to boolean in JavaScript?). You need to determine what the type of variablename is and implement the appropriate comparison.
The difference between 'true' and true is similar to the differences between '3' and 3, or 3.0 and 3. In many cases they will "work". Using these assumptions and implicit coercions is not safe and will eventually cause trouble.
Languages such as JavaScript that support implicit coercions give you plenty of rope. It's up to you to not hang yourself with it.