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

String - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

String , .

In this article

:

' '
" "
" espaol English   portugus      "

, , escape-:

\0 ( NUL)
\'
\"
\\
\n
\r
\v
\t
\b
\f
\uXXXX -
\xXX Latin-1

String :

String(thing)
new String(thing)

thing

, .

, . , + +=, indexOf(), substring().

. charAt():

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

( ECMAScript 5) , :

js
return ""[1]; //  ""

, , , . Object.defineProperty() .

C strcmp(). JavaScript :

js
var a = "a";
var b = "b";
if (a < b) {
  // true
  print(a + "   " + b);
} else if (a > b) {
  print(a + "   " + b);
} else {
  print(a + "  " + b + " .");
}

localeCompare(), String.

String

, JavaScript String ( Boolean Number).

( ) , String ( , new) . JavaScript String, String. , , JavaScript .

js
var s_prim = "foo";
var s_obj = new String(s_prim);

console.log(typeof s_prim); //  'string'
console.log(typeof s_obj); //  'object'

String eval(). , eval(), ; String , , : . :

js
var s1 = "2 + 2"; //   
var 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.length

. .

String.fromCharCode()

, .

String.fromCodePoint()

, .

String.raw()

, .

String

String Firefox JavaScript 1.6 ( ECMAScript) String, :

js
var num = 15;
console.log(String.replace(num, /5/, "2"));

Array.

:

js
/*globals define*/
// ,      String  
// (      ,   )
(function () {
  "use strict";

  var i,
    //       ,  
    //   getOwnPropertyNames()    JavaScript:
    // Object.getOwnPropertyNames(String).filter(function(methodName) {
    //   return typeof String[methodName] === 'function';
    // });
    methods = [
      "quote",
      "substring",
      "toLowerCase",
      "toUpperCase",
      "charAt",
      "charCodeAt",
      "indexOf",
      "lastIndexOf",
      "startsWith",
      "endsWith",
      "trim",
      "trimLeft",
      "trimRight",
      "toLocaleLowerCase",
      "toLocaleUpperCase",
      "localeCompare",
      "match",
      "search",
      "replace",
      "split",
      "substr",
      "concat",
      "slice",
    ],
    methodCount = methods.length,
    assignStringGeneric = function (methodName) {
      var method = String.prototype[methodName];
      String[methodName] = function (arg1) {
        return method.apply(arg1, Array.prototype.slice.call(arguments, 1));
      };
    };

  for (i = 0; i < methodCount; i++) {
    assignStringGeneric(methods[i]);
  }
})();

:

String toString(), toString(), null undefined. :

js
var outputStrings = [];
for (var i = 0, n = inputValues.length; i < n; ++i) {
  outputStrings.push(String(inputValues[i]));
}

Specification
ECMAScript 2027 LanguageSpecification
# sec-string-objects


Web Proxy Viewer  |  New URL  |  Original Page