Convert special characters in a string to their HTML entity equivalents to prevent XSS attacks and ensure safe rendering.
Asked in frontend interviews at Google, Amazon and Microsoft