Recently a colleague at work told me not to use string.Empty
when setting a string variable but use null
as it pollutes the stack?
He says
FWIW, I found that mixing ""
and String.Empty
doesn't work:
var a = "";
alert("a " + (a == "") + ", " + (a==String.Empty)); //Yields "a true, false"
var b = String.Empty;
alert("b " + (b == "") + ", " + (b == String.Empty)); //Yields "b false, true"
In particular, if you use $.trim
to get the value of an empty DOM input field, then compare it to String.Empty
, you get false
. Not sure why that is, but there you go. I now just use ""
everywhere for consistency.