JavaScript escape()

The escape() function in JavaScript is used for encoding a string. It is deprecated in JavaScript 1.5.

Following is the code for the JavaScript escape()


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .sample {
      font-size: 18px;
      font-weight: 500;
<h1>JavaScript escape()</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
Click on the above buttons to encode the URI
   let sampleEle = document.querySelector(".sample");
   let url = "";
   document.querySelector(".Btn").addEventListener("click", () => {
      sampleEle.innerHTML = escape(url);


On clicking the “CLICK HERE” button −