
escape(string) 함수는 문자열 내부의 특수 문자를 HTML로 인코딩하는 함수로, 주로 HTML에서 사용됩니다.
escape(string) 함수는 string 타입의 데이터에만 사용이 가능합니다.
escape(string) 함수를 사용할 때 주의할 점은, escape() 함수는 deprecated 상태로, 대안으로는 String.prototype.encodeURIComponent()를 사용하는 것이 좋습니다.
escape(string) 함수를 사용하는 예시입니다.
#hostingforum.kr
javascript
const str = "Hello, World!";
const escapedStr = escape(str);
console.log(escapedStr); // "Hello%2C%20World!"
// 대안으로는 String.prototype.encodeURIComponent()를 사용할 수 있습니다.
const str2 = "Hello, World!";
const escapedStr2 = encodeURIComponent(str2);
console.log(escapedStr2); // "Hello%2C%20World!"
2025-05-03 21:48