var my_javascript_var = '<%= escape_javascript(my_ruby_expression) %>';
The reason to do that is your ruby expression might contain special symbols ( for example some innocent quotes), making your life excruciatingly painful when all of your javascript code stops working.
This was a direct assignment. However, if you assign a javascript variable using PrototypeHelper, don't escape your ruby expression! If you use:
page.assign 'my_javascript_var', escape_javascript(my_ruby_expression)
you will see your code's html guts on the page.
In this case you need to use:
page.assign 'my_javascript_var', my_ruby_expression
The expression has been already escaped for you by Ruby on Rails.