variable assigned to a boolean won’t echo to the webpage in PHP

I have some PHP code that is supposed to check if a certain value in the $_GET global is assigned. If it isn’t it automatically puts a predetermined value. If there is, it assigns the variable with a default value:

<?php
if(!isset($spaceObjects)){
  $spaceObjects = 0;
} else{
  $spaceObjects = $_GET['spaceObjects'] == true;
}
if(!isset($numOfStars)){
  $numOfStars = 100;
} else{
  $numOfStars = intal($_GET['numOfStars']);
}
if(!isset($starTwinkles)){
  $starTwinkles = 0;
} else{
  $starTwinkles = ($_GET ['starTwinkles'] == true);
}
if(!isset($numOfMeteorsMax)){
  $numOfMeteorsMax = 8;
} else{
  $numOfMeteorsMax = intval($_GET['numOfMeteorsMax']);
}
if(!isset($twinklePausing)){
  $twinklePausing = 1;
} else{
  $twinklePausing = ($_GET['twinklePausing'] == true);
}
if(!isset($nightCycle)){
  $nightCycle = 0;
} else{
  $nightCycle = ($_GET['nightCycle'] == true);
}
if(!isset($music)){
  $music = 1;
} else{
  $music = ($_GET['musicEnabled'] == true);
}
if(!isset($nightSounds)){
  $nightSounds = 0;
} else{
  $nightSounds = ($_GET['nightSounds'] == true);
}
if(!isset($nightSoundsVol)){
  $nightSoundsVol = 0.1;
} else{
  $nightSoundsVol = intval($GET['nightSoundsVol']);
}
?>
let controlVariables = {
  spaceObjects: <?php echo $spaceObjects;?>,
  numOfStars: <?php echo $numOfStars;?>,
  starTwinkles: <?php echo $starTwinkles;?>,
  numOfMeteorsMax: <?php echo $numOfMeteorsMax;?>,
  disableTwinklingWhileSpaceObjectGenerated: <?php echo $twinklePausing;?>,
  nightCycle: <?php echo $nightCycle;?>,
  music: <?php echo $music;?>,
  nightSounds: <?php echo $nightSounds;?>,
  nightSoundsVol: <?php echo $nightSoundsVol;?>
};

What’s weird is that PHP is giving me nothing in some of the echo statements, causing JS to throw a syntax error.

Why instead of printing true or false PHP is giving me nothing for some fields?

Answer

Try to replace echo with condition to output specific text instead of variable itself. Echoed boolean outputs 1 when true, nothing when variable is false. e.g.:

let controlVariables = {
    spaceObjects: <?php echo ($spaceObjects)? 'true' : 'false';?>,
...
}