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

  1. 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) Three Ways to Run JavaScript in VS Code

  2. 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. Three Ways to Run JavaScript in VS Code
    Three Ways to Run JavaScript in VS Code
    2.2 Create a javascript file using Ctrl + P and input > into this bar. And then scroll down if necessary to find “Quokka.js: New javascript file” and press Enter. Three Ways to Run JavaScript in VS Code
    2.3 You can see the file is not saved but the result can be displayed immediately. Three Ways to Run JavaScript in VS Code
    2.4 However, if you want to run a function and see the result, you should type console.log because running a function directly is charged. Three Ways to Run JavaScript in VS Code
    2.5 Finally, you should remember to save the file. After saving, you cannot use this extension to debug it.

  3. 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. Three Ways to Run JavaScript in VS Code
    3.2 You can run like this. Three Ways to Run JavaScript in VS Code
    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. Three Ways to Run JavaScript in VS Code
    3.4 To fix this, you should modify the setting file. Open the settings and search for code runner. Scroll down and click “Edit in settings.json”. Three Ways to Run JavaScript in VS Code
    Three Ways to Run JavaScript in VS Code
    3.5 And follow the picture below to config this json file. Remember to save it. Three Ways to Run JavaScript in VS Code
    3.6 Then, you will only see the current output after clicking the running button.

So far, you have learned how to run javascript file in the VS Code. Hopefully, it helps!

相关文章: