Type coercion issue
On Page 60 section entitled 'Equal and Not Equal'
When performing conversions it states the following:
'If one operand is a string and the other is a number, attempt to convert the string into a number before checking for equality.'
Yet on page 482 in the first example given as follows:
alert(5 == "5")
alert(5 === “5”);
The explanation in the following paragraph states:
'In this code, the number 5 and the string “5” are compared using the equal operator and the identically equal operator. The equal operator first converts the number 5 into the string “5” and then compares it with the other string “5”, resulting in true.'
Page 60 clearly states that under such circumstances a string is converted into a number before checking for equality, but the opposite is being stated in the example on page 482, so the question is which is correct?
Last edited by Mikeos; September 9th, 2010 at 05:12 PM..
|