Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

escape()

Note:escape() is a non-standard function implemented by browsers and was only standardized for cross-engine compatibility. It is not required to be implemented by all JavaScript engines and may not work everywhere. UseencodeURIComponent() orencodeURI() if possible.

Theescape() function computes a new string in which certain characters have been replaced by hexadecimal escape sequences.

Syntax

js
escape(str)

Parameters

str

A string to be encoded.

Return value

A new string in which certain characters have been escaped.

Description

escape() is a function property of the global object.

Theescape() function replaces all characters with escape sequences, with the exception ofASCII word characters (A–Z, a–z, 0–9, _) and@\*_+-./. Characters are escaped by UTF-16 code units. If the code unit's value is less than 256, it is represented by a two-digit hexadecimal number in the format%XX, left-padded with 0 if necessary. Otherwise, it is represented by a four-digit hexadecimal number in the format%uXXXX, left-padded with 0 if necessary.

Note:This function was used mostly forpercent-encoding and is partly based on the escape format inRFC 1738. The escape format isnot anescape sequence in string literals. You can replace%XX with\xXX and%uXXXX with\uXXXX to get a string containing actual string-literal escape sequences.

Examples

Using escape()

js
escape("abc123"); // "abc123"escape("äöü"); // "%E4%F6%FC"escape("ć"); // "%u0107"// special charactersescape("@*_+-./"); // "@*_+-./"

Specifications

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

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp