Question: What is the equivalent javascript code for `mysql_real_escape_string()`?

Answer: 
There isn't any, because strings that come from JavaScript are still considered 'user input' and **should never be inserted in your database directly**. Your server-side has to do additional validation. There are functions to encode URLs and stuff like that. 

What are you trying to do?
I think we can use escape() methode