Why does the variable of the import Loop load module display undefined instead of not defined?

Ruan Yifeng tutorial: http://es6.ruanyifeng.com/-sharpdo...

// a.mjs

import {bar} from "./b";
console.log("a.mjs");
console.log(bar);
export let foo = "foo";
// b.mjs

import {foo} from "./a";
console.log("b.mjs");
console.log(foo);
export let bar = "bar";

in the above code, a.mjs loads b.mjsreb. MJS and then loads a.mjs, which constitutes a circular load. Execute a.mjs, and the result is as follows.

$ node --experimental-modules a.mjs
b.mjs
ReferenceError: foo is not defined

above is the content of the tutorial.

I tested undefined,let in browser environment, didn"t I improve without variable declaration? Why undefined instead of not defined? I have two guesses myself, but neither of them is quite sure. Please give me some advice

May.14,2022

have you changed demo content?
I copy the example test directly no problem

es module environment
deep into CommonJs and ES6 Module


has nothing to do with variable promotion, ES6 is a dynamic reference, the CommonJS specification used in Node environment.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c412-2c2df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c412-2c2df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?