Empty string + variable: why?
The following is a line from Backbone.js
:
return this._escapedAttributes[attr] = escapeHTML(val ==开发者_如何学运维 null ? '' : '' + val);
What is the point of ''
in '' + val
? Wouldn't +val
suffice?
'' + val
concats val
to an empty string, which results in val
being converted to a string. +val
converts val
to a number instead.
精彩评论