Try adding some quotes around the output:
var test = '<%= ViewData["NAME"].ToString() %>'; alert(test);
Edit:
I noticed that you are using NAME for the key; could this name ever have one quote in it? If it is possible that some value will ever contain one, you will want something similar instead, so that your page does not break again (although technically this seems to be more suitable for the controller or model):
var test = '<%= ViewData["NAME"].ToString().Replace("'", "\\'") %>'; alert(test);
source share