Hey guys! Long time no see! Today I will show you how to run JavaScript in VS Code through two different extensions and running in the terminal. Here we go!
Three Ways to Run JavaScript in VS Code
-
If you are a vim-preferred user, you can write a javascript file and run in the terminal using
node xxx.js
. (NOTICE: you should install node and add it into your system environment as prerequisites) -
If you want to get some convenience, you can install the extension.
2.1 First, search for “Quokka.js” in the extension store and install it. This extension helps you have a real-time compilation coding experience.
2.2 Create a javascript file usingCtrl + P
and input>
into this bar. And then scroll down if necessary to find “Quokka.js: New javascript file” and pressEnter
.
2.3 You can see the file is not saved but the result can be displayed immediately.
2.4 However, if you want to run a function and see the result, you should typeconsole.log
because running a function directly is charged.
2.5 Finally, you should remember to save the file. After saving, you cannot use this extension to debug it. -
The last way is using another extension called “code runner”.
3.1 First, search for “Code Runner” and install it. This extension can help you run a javascript file just through clicking a run button.
3.2 You can run like this.
3.3 But you will get annoyed after running a couple of times because the output will accurate in the OUTPUT bar which is such a mess.
3.4 To fix this, you should modify the setting file. Open the settings and search forcode runner
. Scroll down and click “Edit in settings.json”.
3.5 And follow the picture below to config this json file. Remember to save it.
3.6 Then, you will only see the current output after clicking the running button.