Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Encode URL in JavaScript</title> </head> <body> <script> // Sample URL var url = "http://example.com/search.php?product=laptop&price=500#featured"; document.write(url); // Prints: http://example.com/search.php?product=laptop&price=500#featured </script> </body> </html>