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 the difference between "null" and null replace?
I ask because I encountered an error in angularjs:
replace((pctEncodeSpaces ? null : /%20/g), '+');
If, for example, someone had a username "null" and it was used as a url, it would be replaced with a "+" for any calls to $http . e.g. GET /user/null .
Not that this scenario happens often, but I'm more curious why replacing null and "null" calls is the same thing. Does ".tostring" replace with null before replacing? Is this just a javascript fad?
I checked this in both IE and Chrome replace versions.
source share