gpt4 book ai didi

javascript - 如何修复 Node 终端中的 'variable is not defined' 以及为什么会发生这种情况?

转载 作者:太空宇宙 更新时间:2023-11-04 01:31:59 24 4
gpt4 key购买 nike

我定义了一个变量并为其分配了一个有语法错误的函数。它抛出错误。现在,我无法将该变量用于任何用途,它总是显示“抛出:”ReferenceError:变量未定义'

> let bg = 'asasas-123d'
undefined
> let fd = bg.substring(indexOf('-')+1)
Thrown:
ReferenceError: indexOf is not defined
> let fd = bg.substring(bg.indexOf('-')+1)
Thrown:
SyntaxError: Identifier 'fd' has already been declared
> fd = bg.substring(bg.indexOf('-')+1)
Thrown:
ReferenceError: fd is not defined
> let fd = bg.substring(bg.indexOf('-')+1)
Thrown:
SyntaxError: Identifier 'fd' has already been declared
> fd = bg.substring(bg.indexOf('-')+1)
Thrown:
ReferenceError: fd is not defined
> fd
Thrown:
ReferenceError: fd is not defined
> console.log(fd);
Thrown:
ReferenceError: fd is not defined

最佳答案

只需重新启动终端并运行以下命令:

> let bg = 'asasas-123d'
> let fd = bg.substring(bg.indexOf("-") + 1))

关于javascript - 如何修复 Node 终端中的 'variable is not defined' 以及为什么会发生这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55805545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com