const并让假吊装在模块中
我发现在模块级别上拥有Let
和const
时发现了有趣的行为。
func.mjs
export const func = () => {
return num1 + num2;
}
const num1 = 5;
const num2 = 6;
main.mjs
import {func} from 'func.mjs';
console.log(func())
如果您运行node main.mjs
,您将在控制台中获得11
。我可以解释,随着所有模块级别的表达式在导入步骤上定义和初始化。
但是它属于TDZ的概念吗?
I've found interesting behaviour while having let
and const
on module level.
func.mjs
export const func = () => {
return num1 + num2;
}
const num1 = 5;
const num2 = 6;
main.mjs
import {func} from 'func.mjs';
console.log(func())
If you run node main.mjs
, you'll get 11
in console. I can explain that as all module level expressions defined and initialised on import step.
But is it falling under concepts of TDZ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论