Visual Studio Code 中是否有“立即窗口”来运行 Javascript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32700105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:07:09  来源:igfitidea点击:

Is there an "immediate window" in Visual Studio Code to run Javascript?

javascriptvisual-studiointerpreterinteractive-modevisual-studio-code

提问by JzInqXc9Dg

Yes, I use F12 in the browser all the time to test out Javascript snippets with the console. I'm tired of that (for the moment anyway).

是的,我一直在浏览器中使用 F12 来通过控制台测试 Javascript 片段。我已经厌倦了(无论如何)。

I've read that in Visual Studio you can use the immediate window to run Javascript interactively.. I've haven't tried it that hard. I think when I did it told me it can't evaluate while in design mode... ugh, what a pain.

我在 Visual Studio 中读到过,您可以使用即时窗口以交互方式运行 Javascript。我还没有尝试过。我想当我这样做时它告诉我它无法在设计模式下进行评估......呃,真是太痛苦了。

I do like to use Visual Studio Code (sublime text historically) sometimes to just mess around with syntax of snippets. Would also be nice if I could just run Javascript there too quickly. Is there a package I could download in VSCode to do so? Or something already built in?

我确实喜欢使用 Visual Studio Code(历史上是崇高的文本)来处理代码片段的语法。如果我能在那里过快运行 Javascript 也会很好。是否有我可以在 VSCode 中下载的软件包?还是已经内置的东西?

采纳答案by xaxist

There is no Immediate Window unlike Visual Studio in VSCode. But you can still execute Javascript in VSCode.

VSCode 中没有与 Visual Studio 不同的即时窗口。但是你仍然可以在 VSCode 中执行 Javascript。

Install the Code Runner Extension - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

安装 Code Runner 扩展 - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

Open the JavaScript file in VSCode, then use shortcut Ctrl+Alt+N, the code will run and the output will be shown in the Output Window.

在 VSCode 中打开 JavaScript 文件,然后使用快捷键Ctrl+ Alt+ N,代码将运行并且输出将显示在输出窗口中。

回答by Craig Walker

As of (at least) my current version of VS Code (1.5.2), the "Debug Console", while debugging, lets you run arbitrary JavaScript code as you would in the VS Immediate Window. (Similar to as you would for the Chrome Dev Tools Console.)

从(至少)我当前版本的 VS Code (1.5.2) 开始,“调试控制台”在调试时可让您像在 VS 即时窗口中一样运行任意 JavaScript 代码。(类似于 Chrome 开发工具控制台。)

回答by Checo R

I've found this extension that makes a scrathpad for JS, that runs at the same time as you are typing: https://quokkajs.com/

我发现这个扩展为 JS 制作了一个 scrathpad,它在您输入的同时运行:https://quokkajs.com/

Works on VS Code, Jet Brains, and Atom.

适用于 VS Code、Jet Brains 和 Atom。

回答by Strategy Thinker

Run the command nodein the terminal below the editor, this will create a node environment where arbitrary JavaScript can be entered. You must first have node (and apparently npm) installed from nodejs.

node在编辑器下方的终端中运行命令,这将创建一个可以输入任意 JavaScript 的节点环境。您必须首先从nodejs安装节点(显然是 npm)。

回答by JzInqXc9Dg

This might do it: https://code.visualstudio.com/Docs/runtimes/nodejs

这可能会做到:https: //code.visualstudio.com/Docs/runtimes/nodejs

Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js is the runtime and NPM is the Package Manager for Node.js modules.

To get started, install Node.js for your platform. The Node Package Manager is included in the Node distribution.

Node.js 是一个使用 JavaScript 构建快速且可扩展的服务器应用程序的平台。Node.js 是运行时,NPM 是 Node.js 模块的包管理器。

首先,为您的平台安装 Node.js。节点包管理器包含在节点分发中。