Three Ways to Run JavaScript in VS Code

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_1.png

  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_2.png
    Three_Ways_to_Run_JavaScript_in_VS_Code_3.png
    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_4.png
    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_5.png
    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_6.png
    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_7.png
    3.2 You can run like this. Three_Ways_to_Run_JavaScript_in_VS_Code_8.png
    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_9.png
    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_10.png
    Three_Ways_to_Run_JavaScript_in_VS_Code_11.png
    3.5 And follow the picture below to config this json file. Remember to save it. Three_Ways_to_Run_JavaScript_in_VS_Code_12.png
    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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值