test.html
<script type="module" src="./B.js"></script>
A.js
import {bar} from './B.js';
import {test} from './B.js';
export function foo() {
bar();
}
test();
console.log("IN A");
B.js
import {foo} from './A.js';
export function bar() {
if (Math.random()) {
foo();
}
}
export function test() {
console.log("test");
}
console.log("IN B");
The output is:
B.js:30 test
A.js:24 IN A
B.js:33 IN B
Why is "In B" the last line of code that gets executed? Also, if in test.html, src="./A.js"
, "IN B" is the first line that gets executed.