The code:
var num = 20;
if(num == 20)
{
alert(It works);
}
else
{
alert(Not working);
}
The question:
In C programming we have a rule name data type promotion, where when there's a mix of data type (example: addition of integer and floating point), the integer will first converted to floating point before the addition is being carry out.
The code above will prompt me an alert box with the message
It works
that shows theif
test condition is evaluate to true.For loosely typed JavaScript, I'm just curious: is there any rule like C that determines which conversion will be carry out in which situation? Besides that, the JavaScript code above converts
num
variable value from an integer value to string value before making comparison or vice versa?