var p = "null"
var q = null;
(p == q) //false. as Expected.
p.replace(null, "replaced") // outputs replaced. Not expected.
p.replace("null", "replaced") //outputs replaced. Expected.
q.replace(null, "replaced") // error. Expected.
q.replace("null", "replaced") //error. Expected.
Why? Does replace not differentiate between "null" and null?
I ask because I ran into a bug in angularjs:
replace((pctEncodeSpaces ? null : /%20/g), '+');
If for example, someone had a username of "null" and it was used as url, it would be replaced with "+" on any $http calls. e.g. GET /user/null.
Not that this scenario would occur often, but I'm more curious why replace treats null and "null" as the same thing. Does replace do a .tostring on null before it does the replacement? Is this just a quirk of Javascript?
I verified this on both IE and Chrome's implementations of replace.
qpart is just distracting.