Re:PHP: md5('240610708') == md5('QNKCDZO')
by adamzochowski on Monday May 04, 2015 @11:18AM
(#9486671)
Yes, JavaScript will convert strings into numbers
console.log(5*"12");
60
console.log(5*"0x0C");
60Actually, sometimes type conversion make some code become a little bit handy.
We use Java at the backend and of course Javascript for frontend. When serializing, in Java we should
String dataRaw = "42";
int objectId = Integer.parseInt(dataRaw);
Meanwhile, in JS, it is fairly simple: dataRaw = "42";
var objectid = +dataRaw;12 is not 0.
Yes and no. JavaScript gives you the good ol' "NaN" which is a number (despite not being a number).
PHP doesn't have that concept in it.
Sort of. 'NaN' is one of the IEEE 754 floating point constants, along with 'Inf' for infinity. They are numeric types, in that they can be returned via operations on numbers, such as dividing zero by zero or adding '-Inf' to 'Inf'. See https://en.wikipedia.org/wiki/NaN
I always understood that the 'isNaN()' function was required to check if a numeric variable is equal to 'NaN' directly, since normal equality cannot be used as there are multiple valid bitwise representations of 'NaN' in the standard - it is a float with an exponent of all ones and a non-zero fraction. However, 'isNaN()' now seems to have been co-opted into being used to check if a string is not a number, i.e. does not represent a numeric value, and in fact I believe this is now the documented description of the function in ECMAScript?
Re:PHP: md5('240610708') == md5('QNKCDZO')
by DonHopkins on Tuesday May 05, 2015 @08:51AM
(#9492146)
gNaN's Not a Number
Even JavaScript isn't insane enough to somehow coerce a string to 0.