How can I compare a value from C# Viewbag in Javascript?
What you have should work, assuming that the value from the ViewBag is of a type which javascript can understand.
Note however, that your first example most likely did not work because boolean values are lowercase in javascript and uppercase in C#. With that in mind, try this:
var myBoolValue = @ViewBag.MyBoolValue.ToString().ToLower();
if (myBoolValue)
do_sth();