OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Javascript access global variable from inside the module

  • Thread starter Thread starter Lukáš Ježek
  • Start date Start date
L

Lukáš Ježek

Guest
I am trying to access a global variable or a function from inside the module, but it still writes error that testFunction is not defined.

index.html

Code:
<script src="main.js" type="module">

main.js

Code:
import { runTestFunction } from './js/TestModule.js';

function testFunction() {
    alert('hello');
}

runTestFunction();

TestModule.js

Code:
export function runTestFunction() {
    testFunction();
}

<p>I am trying to access a global variable or a function from inside the module, but it still writes error that testFunction is not defined.</p>
<p>index.html</p>
<pre class="lang-html prettyprint-override"><code><script src="main.js" type="module">
</code></pre>
<p>main.js</p>
<pre class="lang-js prettyprint-override"><code>import { runTestFunction } from './js/TestModule.js';

function testFunction() {
alert('hello');
}

runTestFunction();
</code></pre>
<p>TestModule.js</p>
<pre class="lang-js prettyprint-override"><code>export function runTestFunction() {
testFunction();
}
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top