Hi I’m just going over some basic javascript and I came across this piece of code
if('3'!=3)
{
document.write("Hello");
}
This writes hello to the screen, however when I change it to:
if('3'==3)
{
document.write("Hello");
}
This also writes Hello to the screen
Does anyone know any reason for this? I read that javascript converts a string to a number in a comparison I just dont understand the different behavior when I change the condition
Thanks !!
If you want to do a strict comparison use the
===operator or!==