Q:

Visual Studio Razor Page False Syntax Errors

Whenever I use the @ sign with a Razor page, such as this:
<script type="text/javascript">
if( @(ProjectName.NameSpace.booleanVariable) ) {
    doStuff();
}
</script>

then I get syntax error notifications all over the place that turn out fine after the conversion to HTML:
<script type="text/javascript">
if(True) {
    doStuff();
}
</script>

This is just a simple example but it occurs in other places as well. I will cite other examples if they become necessary. I couldn't find an answer among other stackoverflow questions, but with such a basic question I assume one is around. Links to said question are encouraged.
edit: Realized I should show that examples are JS inside Razor Page.
Question Is: How do I prevent these syntax error notifications so that I can identify and manage real syntax errors easily.

A:

I don't think "True" is a valid javascript.
<script type="text/javascript">
if( Boolean(@Html.Raw(Json.Encode(ProjectName.NameSpace.booleanVariable))) ) {
    doStuff();
}
</script>

Boolean() is javascript code, to avoid the Razor Warning message.
Json.Encode to convert booleanVariable to "true" or "false", 
you can replace it with (ProjectName.NameSpace.booleanVariable ? "true" : "false")
I think what you really want is
@if(ProjectName.NameSpace.booleanVariable) {
{<script type="text/javascript">
    doStuff();
</script>}
}

