title: Js catch if variable was changed by js
body: <p>I have 2 buttons which are change status of variable, If status is 1 it shows div, if not it hides dive. I need to catch this variables changes and add condition inside different script, which will work without page refresh and will add or hide script depends on variable.
  Here is example code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var point_access = 0;
  
  document.getElementById('button 1').onclick = function() {
    if (point_access == 0) {
      point_access = 1;
      //do smth else
    }
  }
  
  document.getElementById('button 2').onclick = function() {
    if (point_access == 1) {
      point_access = 0;
      //do smth else
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is the code that I want to show or hide script, which is depends on variable <code>point_access</code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        //smth here
      }),
      new ol.layer.Tile({
        //smth here
      }),
      vectorLayer //this is the variable inside script which i want to show or hide
      //if(point_access == 1){
      //  vectorLayer
      //}
    ],
    //smth else
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>So, how can I do it work live? It all time get <code>point_access</code> value as <code>0</code> and do not listen to my value change on click.</p>