[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String [Back]  [Original]

String - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String

Baseline *

20157

*

String

length + += indexOf() substring()

String()

js
const string1 = "";
const string2 = '';
const string3 = ``;
js
const string4 = new String("");

String

`

2 charAt()

js
"".charAt(1); // "" 

js
""[1]; // "" 

Object.defineProperty()

/

js
const a = "a";
const b = "b";
if (a < b) {
  // true
  console.log(`${a}  ${b} `);
} else if (a > b) {
  console.log(`${a}  ${b} `);
} else {
  console.log(`${a}  ${b} `);
}

=== ==

js
function areEqualCaseInsensitive(str1, str2) {
  return str1.toUpperCase() === str2.toUpperCase();
}

toUpperCase() toLowerCase() ss toUpperCase() SS toLocaleLowerCase("tr") toLowerCase() I

js
const areEqualInUpperCase = (str1, str2) =>
  str1.toUpperCase() === str2.toUpperCase();
const areEqualInLowerCase = (str1, str2) =>
  str1.toLowerCase() === str2.toLowerCase();

areEqualInUpperCase("", "ss"); // true; should be false
areEqualInLowerCase("", "I"); // false; should be true

Intl.Collator API localeCompare() sensitivity "accent" "base"

js
const areEqual = (str1, str2, locale = "en-US") =>
  str1.localeCompare(str2, locale, { sensitivity: "accent" }) === 0;

areEqual("", "ss", "de"); // false
areEqual("", "I", "tr"); // true

localeCompare() strcmp()

String

JavaScript String Boolean Number

String new JavaScript

js
const strPrim = "foo"; // 
const strPrim2 = String(1); //  "1" 
const strPrim3 = String(true); //  "true" 
const strObj = new String(strPrim); // new  String 

console.log(typeof strPrim); // "string"
console.log(typeof strPrim2); // "string"
console.log(typeof strPrim3); // "string"
console.log(typeof strObj); // "object"

: String

String eval() eval String

js
const s1 = "2 + 2"; // 
const s2 = new String("2 + 2"); // String 
console.log(eval(s1)); //  4 
console.log(eval(s2)); //  "2 + 2" 

String

String valueOf()

js
console.log(eval(s2.valueOf())); //  4 

String

JavaScript

`${x}` String(x) "" + x

UTF-16 Unicode

UTF-16 UTF-16 16 UTF-16 216 65536 (BMP) u 4 16

Unicode 65536 UTF-16 16 2 0xD800 0xDFFF 0xD8000xDBFF0xDC00 0xDFFF Unicode \u{xxxxxx} xxxxxx 1-6 16

16

  • 0xD800 0xDBFF
  • 0xDC00 0xDFFF

Unicode UTF-16 JavaScript encodeURI() URIError URI UTF-8 well-formed UTF-16 encodeURI() TextEncoder isWellFormed() toWellFormed()

Unicode 1 Unicode <ZWJ> (U+200D)

split("") UTF-16 UTF-16 [Symbol.iterator]() Unicode

js
"".split(""); // ['\ud83d', '\ude04'];  2 

// "Backhand Index Pointing Right: Dark Skin Tone"
[...""]; // ['', '']
//  "Backhand Index Pointing Right" 
// "Dark skin tone" 

// "Family: Man, Boy"
[...""]; // [ '', '', '' ]
// "Man"  "Boy"  ZWJ 

// 
[...""]; // [ '', '' ]
// 2  "region indicator"  "U"  "N"
// 2 

String()

String String

String.fromCharCode()

Unicode

String.fromCodePoint()

Unicode

String.raw()

String.prototype String

String.prototype.constructor

String

String

length

length

String.prototype.at()

index UTF-16

String/charAt

index UTF-16 1

String.prototype.charCodeAt()

index UTF-16

String.prototype.codePointAt()

pos UTF-16

String.prototype.concat()

2

String.prototype.endsWith()

searchString

String.prototype.includes()

searchString

String.prototype.indexOf()

searchValue -1

String.prototype.isWellFormed()

String.prototype.lastIndexOf()

searchValue -1

String.prototype.localeCompare()

compareString

String.prototype.match()

regexp

String.prototype.matchAll()

regexp

String.prototype.normalize()

Unicode

String.prototype.padEnd()

targetLength

String.prototype.padStart()

targetLength

String.prototype.repeat()

count

String.prototype.replace()

searchFor replaceWith searchFor replaceWith

String.prototype.replaceAll()

searchFor replaceWith searchFor replaceWith

String.prototype.search()

regexp

String.prototype.slice()

String.prototype.split()

sep

String.prototype.startsWith()

searchString

String.prototype.substr()

String/substring

String.prototype.toLocaleLowerCase()

toLowerCase()

String.prototype.toLocaleUpperCase()

toUpperCase()

String.prototype.toLowerCase()

String.prototype.toString()

Object.prototype.toString()

String.prototype.toUpperCase()

String.prototype.toWellFormed()

Unicode U+FFFD

String.prototype.trim()

String.prototype.trimEnd()

String.prototype.trimStart()

String/valueOf

Object.prototype.valueOf()

String.prototype[Symbol.iterator]()

HTML

String.prototype.anchor()

<a name="name">

String.prototype.big()
<big>

<blink>

String.prototype.bold()
<b>
String.prototype.fixed()
<tt>
String.prototype.fontcolor()

<font color="color">

String.prototype.fontsize()

<font size="size">

String.prototype.italics()
<i>

<a href="url">URL

String.prototype.small()
<small>
String.prototype.strike()
<strike>
String.prototype.sub()
<sub>
String.prototype.sup()
<sup>

HTML HTML

js
"</b>".bold(); // <b></b></b>

" anchor()fontcolor()fontsize()link()&quot;

js
"foo".anchor('"Hello"'); // <a name="&quot;Hello&quot;">foo</a>

String() toString() null undefined

js
// null  undefined 

const nullVar = null;
nullVar.toString(); // TypeError: Cannot read properties of null
String(nullVar); // "null"

const undefinedVar = undefined;
undefinedVar.toString(); // TypeError: Cannot read properties of undefined
String(undefinedVar); // "undefined"

ECMAScript 2027 LanguageSpecification
# sec-string-objects


Web Proxy Viewer  |  New URL  |  Original Page