Define unescape() and escape() functions?
The escape() function was used to encode a string by replacing non-ASCII and special characters with their hexadecimal Unicode escape sequences.
In this example, spaces were encoded as %20, and the exclamation mark was encoded as %21.
The unescape() function was used to decode a string encoded with the escape() function, converting hexadecimal escape sequences back to their original characters.
However, both escape() and unescape() have issues with encoding and decoding certain characters, and they don't provide adequate protection against URL manipulation attacks. As a result, they are considered obsolete and should be avoided.
The encodeURIComponent() function ensures that the resulting encoded string is safe for inclusion in a URL, addressing some of the vulnerabilities of the old escape() function. Similarly, decodeURIComponent() decodes a URL-encoded string back to its original form. These functions provide better support for international characters and are recommended for modern web development.