serialize-javascript securely serializes JavaScript values into a superset of JSON that includes regular expressions, Dates, and functions. It mitigates XSS risks by escaping unsafe characters and HTML metacharacters. Useful for embedding JavaScript data directly into HTML, particularly when server-side rendering. Handles circular references and prevents prototype pollution. Offers options to specify unsafe mode, allowing potentially dangerous JavaScript to be serialized when needed, but requires caution.