Pass Craft Field String to Javascript Function I tried different solutions given here, here and here.
But I get nothing to work, probably missing something small and simple.

I have this variable in a .js File:  

var dziFilesUrl = 'http://localhost:3000/openseadragon/highres/{{ entry.kelimImageData }}/';
var dziData = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;Image xmlns="http://schemas.microsoft.com/deepzoom/2008" Format="jpeg" Overlap="1" TileSize="254"&gt;&lt;Size Height="5097" Width="3600"/&gt;&lt;/Image&gt;';


where I want the entry.kelimImageData coming from the Backend.

In my .twig File i have this:  

{% includeJsFile "/assets/js/openseadragon-custom-dzi.js" %}

{% set myJs %}
  tileSourceFromData('{{entry.kelimImageData}}');
{% endset %} 

{% includeJs myJs %}` 


My openseadragon-custom-dzi.js File looks like this (modified to make it not so long)  

var dziFilesUrl = 'http://localhost:3000/openseadragon/highres/{{ entry.kelimImageData }}/';
var dziData = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;Image xmlns="http://schemas.microsoft.com/deepzoom/2008" Format="jpeg" Overlap="1" TileSize="254"&gt;&lt;Size Height="5097" Width="3600"/&gt;&lt;/Image&gt;';

var tileSourceFromData = function(data, filesUrl) {
  var $xml = $($.parseXML(data));
  var $image = $xml.find('Image');
  var $size = $xml.find('Size');
  var dzi = {
    Image: {
      xmlns: $image.attr('xmlns'),
      Url: filesUrl,
      Format: $image.attr('Format'),
      Overlap: $image.attr('Overlap'),
      TileSize: $image.attr('TileSize'),
      Size: {
        Height: $size.attr('Height'),
        Width: $size.attr('Width')
      }
    }
   return dzi;
  }; 
}


var viewer = OpenSeadragon({
  ...
  tileSources: tileSourceFromData(dziData, dziFilesUrl)
});
Craft 3

According to the craft 3 js docs

We'll need to adjust some things as follows:

Twig

We no longer need to tell craft which File we're editing as it 
now simply inserts a &lt;script&gt; tag with the contents at the end of the &lt;body&gt; tag. (Can be adjusted, see position docs.)

{% js %}
// define our vars
var dziFilesUrl = "http://localhost:3000/openseadragon/highres/{{ entry.kelimImageData }}/";
var dziData = "{{ entry.kelimImageData }}";
//Call our function
tileSourceFromData(dziData, dziFilesUrl);
{% endjs %}


JS

Remove the dziFilesUrl declaration from openseadragon-custom-dzi.js &amp; and other files you declare this variable in.

And that about sums it up, if any error does occur, please inform me of whatever error your browser console spews out or otherwise any error craft presents.

Craft 2

I'm gonna guess that you're using craft cms v2 as I only found includeJS in the craft 2 docs. 

Adjust your twig as follows:

{%includeJsFile "" %}

{% set myJs %}
  // here you're setting the vars which use the twig variables for them to be available later on in the JS
  var dziFilesUrl = "http://localhost:3000/openseadragon/highres/{{ entry.kelimImageData }}/";
  var dziData = "{{ entry.kelimImageData }}";

  // you could even still call your `tileSourceFromData` function here
  tileSourceFromData(dziData, dziFilesUrl);
{% endset %} 

{% includeJs myJs %}` 


And then remove the setting of those vars in your openseadragon-custom-dzi.js.

This should:


Set the vars with the backend data in the Footer (see docs)
Call the tileSources function in the footer as you did before.
Allow you to use the dziFilesUrl and the dziData variables anywhere else in your JS with the backend data as their values.


Beware: This JS is getting executed in the footer according to the docs so you need to either start your function call from within the twig myJs or when the full page is loaded, otherwise you'll run into undefined variables.

Sidenote: you were calling your tileSourceFromData function in the twig with only one arg, instead of the required two before, this is also adjusted in my answer.