What does the following code demonstrate about the module system? // a.js import { b } from ‘./b.js’; export const a = 1; // b.js import { a } from ‘./a.js’; export const b = a + 1;

JavaScript Professional Hard

JavaScript Professional — Hard

What does the following code demonstrate about the module system? // a.js import { b } from ‘./b.js’; export const a = 1; // b.js import { a } from ‘./a.js’; export const b = a + 1;

Key points

  • Circular dependencies can lead to issues with variable access timing
  • In this case, b.js tries to access a from a.js before it is fully defined
  • This can cause b to receive undefined due to the timing of execution

Ready to go further?

Related questions