开发者

Empty string + variable: why?

开发者 https://www.devze.com 2023-04-05 06:24 出处:网络
The following is a line from Backbone.js: return this._escapedAttributes[attr] = escapeHTML(val ==开发者_如何学运维 null ? \'\' : \'\' + val);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消