Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何摆脱ReferenceError:Java脚本中没有定义窗口,这意味着什么?_Javascript_Node.js - Fatal编程技术网

Javascript 如何摆脱ReferenceError:Java脚本中没有定义窗口,这意味着什么?

Javascript 如何摆脱ReferenceError:Java脚本中没有定义窗口,这意味着什么?,javascript,node.js,Javascript,Node.js,我刚刚开始学习JavaScript,正在使用Atom文本编辑器,并安装了NodeJS v14.7.0版本。 我只写了一行代码:-- 当我使用ctrl+shift+B运行程序时,我遇到了一个看起来不像任何语法错误的错误 下面我将发布错误。 window.alert('Hello World'); ^ ReferenceError: window is not defined at [stdin]:58:1 at Script.runInThisContext (vm.js:132

我刚刚开始学习JavaScript,正在使用Atom文本编辑器,并安装了NodeJS v14.7.0版本。 我只写了一行代码:--

当我使用ctrl+shift+B运行程序时,我遇到了一个看起来不像任何语法错误的错误

下面我将发布错误。

window.alert('Hello World');
^

ReferenceError: window is not defined
    at [stdin]:58:1
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:315:38)
    at Object.<anonymous> ([stdin]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at evalScript (internal/process/execution.js:98:25)
    at internal/main/eval_stdin.js:29:5
    at Socket.<anonymous> (internal/process/execution.js:211:5)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1244:12)
[Finished in 8.238s]
   
window.alert('Hello World');
^
ReferenceError:未定义窗口
at[stdin]:58:1
位于Script.runInThisContext(vm.js:132:18)
在Object.runInThisContext(vm.js:315:38)
反对。([stdin]-包装器:10:26)
at模块编译(内部/modules/cjs/loader.js:1256:30)
在evalScript(internal/process/execution.js:98:25)
在内部/main/eval_stdin.js:29:5
在插座上。(internal/process/execution.js:211:5)
在Socket.emit(events.js:326:22)
在endReadableNT(_stream_readable.js:1244:12)
[以8.238s完成]
我也用Webstorm运行它,但不幸的是它没有帮助。 我在谷歌上搜索了一下,但无法理解问题所在。 请帮我摆脱这个困境。
提前谢谢。。
你的话对我来说很有价值。

制作一个运行脚本的HTML文件:

test.html


script.js

window.alert(“你好我自己”);

使用ctrlaltB启动浏览器是有办法的,但现在,用Chrome之类的web浏览器打开
test.html
文件。

window
是web浏览器中的一个全局变量。Node.js中有一个名为
global
的全局变量,但是它没有
alert
方法。所以我要做的事情请解释。好的,我理解,但我从一个视频讲座中学习,对于他来说,不使用html文件,他就能够运行这个程序。顺便说一句,谢谢。我感谢你的帮助。那么,这个讲座可能会指导如何设置项目。你可能错过了。
window.alert('Hello World');
^

ReferenceError: window is not defined
    at [stdin]:58:1
    at Script.runInThisContext (vm.js:132:18)
    at Object.runInThisContext (vm.js:315:38)
    at Object.<anonymous> ([stdin]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at evalScript (internal/process/execution.js:98:25)
    at internal/main/eval_stdin.js:29:5
    at Socket.<anonymous> (internal/process/execution.js:211:5)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1244:12)
[Finished in 8.238s]