4 ms·
> if (Session["startDate"] + "" == "") This feels horribly familiar. I'm not sure to recognize the specific language used, but there must be cases where one wo
by hrktb 13y ago
> if (Session["startDate"] + "" == "")
This feels horribly familiar. I'm not sure to recognize the specific language used, but there must be cases where one would like to target empty of filled with non processable characters strings only, and let null and falsy values pass through. This kind of use would typically need a line of comment, but hey...
- goldenkey 13y agoI'm guessing you don't realize that the plus operator has less precedence than the == operator. That if is equivalent to if (startDate + true) EDIT: I was wrong. I haven't slept.
- danielweber 13y agoI shell languages I do this a lot. if "x$VARIABLE" == "x" because it handles the cases where $VARIABLE is undefined or multiple words without vomiting all over the place.
- viraptor 13y agoI hate when people do that because it's not needed at all. The quoting already fixes everything. if [[ "$VARIABLE" == "" ]] or even better if [ -z "$VARIABLE" ] will handle undefined, empty and multiple words just fine.
- twic 13y agoUnless you're running with -u, which you should be, in which case it will blow up on an undefined variable. To treat undefined as empty, you want: if [[ -z "${VARIABLE:-}" ]]
- statictype 13y agoDo this in javascript all the time. Adding a `+ ""` forces the object to become a string. Though not sure why it was required for this particular comparison.