47

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).

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.

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?

7
  • Maybe I can try visualstudio.com/en-us/features/node-js-vs.aspx which suggests to install node.js tools for VS. Maybe there is something similar for VS Code Sep 21, 2015 at 16:26
  • 1
    Do you want to run server-side JavaScript (on their computer) or client side (on yours)? Sep 21, 2015 at 16:47
  • 1
    Not even interested in doing it for anything production-wise. It's more for my own development style of "hey I need to figure out some syntax really quickly. I don't want to deploy even to my test environment to test out the code.. I just need to quickly see some output" Sep 21, 2015 at 16:48
  • I think VSC's new window is meant to evaluate complex expressions while nodejs is running; eg, find a value accessible via method, inside an important object. It wasn't meant for simply evaluating expressions from a neutral state. For that, use either a browser window or NodeJS in interactive mode. You can also try using a site like JSFiddle.
    – Katana314
    Sep 21, 2015 at 17:26
  • 1
    You can set up Run configurations in VSCode to simply run a JS file you have through NodeJS, even if it quits with a simple output. You can set up one such file to just be a "test project" you use for trying out features before coding them in.
    – Katana314
    Sep 21, 2015 at 17:42

6 Answers 6

42

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.)

2
  • 1
    Debug Console also executes C# commands in the current debug scope, no need for an extension imo. This should be the accepted answer Dec 28, 2021 at 16:41
  • There are use cases to run code while not debugging. Sep 18 at 15:22
34

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

Install the Code Runner Extension - 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.

2
  • 1
    Note: If you don't want to save or open an existing file, you can also use Change Language Mode (shortcut Ctrl + K M) on a new untitled tab.
    – davidmdem
    Jan 3, 2019 at 18:01
  • This answer is from 2017. I just tried with latest VCode in Linux, from Terminal, run Node<ENTER>. Node must be installed and on path... see @Diego's answer below, and upvote it if helpful. I upvoted this and Diego's answer.. this answer was helpful before and provides contextual history of the issue, while Diego's answer seems most relevant today. Thanks to both!
    – Ashley
    Mar 10 at 0:05
9

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

Works on VS Code, Jet Brains, and Atom.

9

If you don't want to start a debugging session or installing an extension, a simple way to have a JavaScript console is to start Node in a Terminal.

  1. View -> Terminal
  2. Start node (without any argument -you'll need node in your PATH)
  3. Now you have a repl with auto-complete and value preview.

It doesn't have the features of the Chrome Console, but I find it good enough for evaluating JS code while I'm working.

1

Run the command node in 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.

-2

This might do it: 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.

1
  • This comment is not relevant here. Sep 30, 2022 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.