What you have should work if you assume that the value from the ViewBag is of a type that javascript understands.
Please note, however, that your first example most likely did not work, because booleans are lowercase in javascript and uppercase in C #. With that in mind, try this:
var myBoolValue = @ViewBag.MyBoolValue.ToString().ToLower();
if (myBoolValue)
do_sth();