To pass scalar data held in a PHP variable (
var val = "
<?php echo $val ?>";
Here we demonstrate with boolean, numeric, and string values assigned to PHP variables:
<?php $bool = false; $num = 3 + 4; $str = "A string here"; ?>
json_encode function can be used to resolve these problems as well as to preserve data type of booleans and numbers.