Javascript – use a VB variable inside of an Embedded Javascript section

Is it possible to do something like this:

<% Dim foo as string = "bar" %>

<script type="text/javascript">
    var baz = <%=foo %>

Where the <script> tag is embedded on my index page?

Best Solution

Yes, but make sure you put quotes around it and a semicolon:

var baz = '<%=foo %>';