The only thing I can think of is that the smarty expression is running regardless of the js code. I think in the newer versions you don't even have to use the literal tag if they are on their own line. So basically you have the last one overwriting even though you think it shouldn't run.
There is no need to do this though.
Code:
{assign var="testB" value=false } {* initial value is assigned *}
<script>
var test;
test = Math.round(Math.random()) == 1;
if (test) {ldelim}
{assign var="testB" value=true}
{rdelim}
</script>
You can even inline the first 2 lines so it is like
var test = Math.round(Math.random()) == 1
See if this works