Hướng dẫn string operators in javascript

[link to URL]

String.prototype.small[] DeprecatedString.prototype.strike[] DeprecatedString.prototype.sub[] DeprecatedString.prototype.sup[] Deprecated

Note that these methods do not check if the string itself contains HTML tags, so it's possible to create invalid HTML:

"".bold[]; // 

The only escaping they do is to replace " in the attribute value [for anchor[], fontcolor[], fontsize[], and link[]] with ".

"foo".anchor['"Hello"']; // foo

Examples

String conversion

It's possible to use String as a more reliable toString[] alternative, as it works when used on null and undefined. For example:

const nullVar = null;
nullVar.toString[];       // TypeError: nullVar is null
String[nullVar];          // "null"

const undefinedVar = undefined;
undefinedVar.toString[];  // TypeError: undefinedVar is undefined
String[undefinedVar];     // "undefined"

Specifications

Specification
ECMAScript Language Specification
# sec-string-objects

Browser compatibility

BCD tables only load in the browser

See also

Bài Viết Liên Quan

Toplist mới

Bài mới nhất

Chủ Đề