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

escape()

Deprecated

Avoid using this feature in new projects. TC39 included the escape() and unescape() methods in Annex B of the ECMAScript specification, which covers JavaScript features with "one or more undesirable characteristics and in the absence of legacy usage would be removed." This feature may be a candidate for removal from web standards or browsers.

Устаревший метод escape() возвращает новую строку, в которой определённые символы заменены шестнадцатеричной управляющей последовательностью. Используйте методы encodeURI или encodeURIComponent вместо него.

Синтаксис

escape(str)

Параметры

str

Строка для кодирования.

Описание

Функция escape() является свойством глобального объекта, т.е. относится к глобальным функциям. Эта функция кодирует специальные символы, за исключением: @*_+-./

The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: %xx. For characters with a greater code unit, the four-digit format %uxxxx is used.

Примеры

js
escape("abc123"); // "abc123"
escape("текст"); // "%u0442%u0435%u043A%u0441%u0442"
escape("ć"); // "%u0107"

/* специальные символы */
escape("@*_+-./"); // "@*_+-./"

Спецификации

Specification
ECMAScript® 2027 Language Specification
# sec-escape-string

Совместимость с браузерами

Смотрите также