How to add a JS function in a script block in JavaScript : <p>I need to create the below below element and add this to head section of the HTML file.</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-html lang-html prettyprint-override"><code>    &lt;script type="text/javascript"&gt;
	//Var declarations - ABCCD
        (function(d) {
            //FUNCTION CODES
        }(document));
    &lt;/script&gt;</code></pre>
</div>
</div>
</p>

<p>Everything is done but I am just getting issue with the above mentioned part. I have tried different options, but not able to add the function as it is mentioned.</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-html lang-html prettyprint-override"><code>var headtg = document.getElementsByTagName('head')[0];
var divElm = document.createElement('div');
var scpt = document.createElement('script');
scpt.type = 'text/javascript';

var A = "100";

    var myfunc1 = function(d) {
            //LINES OF CODE
        }(document);

divElm.className = "ABC_" + A;
divElm.appendChild(scpt);
headtg.appendChild(divElm);

//Var declaration part
var decvar = 'var A = 10;'
scpt.appendChild(document.createTextNode(decvar));
    
scpt.innerHTML = myfunc1;</code></pre>
</div>
</div>
</p>

<p>But the function is not coming up within the script block and coming up as undefined.</p>

<p>Please help</p>
