How can I pass a variable to javascript from a preprocess function?
send it:

function mytheme_preprocess_page(&amp;$variables) {
   $variables['#attached'] = [
        'drupalSettings' =&gt; [
          'myLibrary' =&gt; [
            'is_front' =&gt; $variables['is_front'],
          ],
        ],
    ];
}


access it in jquery:

  Drupal.behaviors.myBehaviour = {
    attach: function (context, settings) {

      console.log(settings.myLibrary.is_front);

    }
  };