title: Passing php variables to javascript in laravel syntax errors
body: <p>Question 1)
  When passing PHP variables to be used in javascript if the variables hold an array, it will result in an error relating to the attempted conversion of array to string when trying to pass these values in the following manner. Why do I have to json encode the value before it works when $var itself is already an array?</p>
  <p>PHP Code</p>
  <pre><code>$var = ['test'];
  </code></pre>
  <p>Javascript</p>
  <pre><code>Let var = {!!$var!!};
  </code></pre>
  <p>Solution</p>
  <pre><code>Let var = {!!json_encode($var)!!} 
  </code></pre>
  <p>Question 2 when passing PHP variables that may have the value of null to javascript, it may result in a syntax error. For example,</p>
  <p>PHP Code</p>
  <pre><code>$var = null;
  </code></pre>
  <p>Javascript</p>
  <pre><code>Let var = {{$var}};
  </code></pre>
  <p>Error</p>
  <pre><code>Var = ; (Syntax error)
  </code></pre>
  <p>Failed Solution</p>
  <pre><code>if({{$var}}){
      let var = {{$var}};
  </code></pre>
  <p>Solution</p>
  <pre><code>Let var = '{{$var');
  </code></pre>
  <p>Why does my attempted solution of only setting the value of the var when $var has a value fails?</p>