How To Run JavaScript Code In Visual Studio Code

by David Valdez
How To Run JavaScript Code In Visual Studio Code

You’re probably familiar with the concept of creating a script file that runs automatically after your code is checked in. But did you know that you can also have your scripts run automatically when you start coding? Visual Studio Code has built-in support for running JavaScript code in files. This means that you can use the text editor and its integrated debugger to write JavaScript and execute it automatically whenever you create a new script file. And if you’re an avid VSC user, you’ll be happy to know that Visual Studio Code supports both NodeJS and TypeScript out of the box! In this article, we’ll explore how to run JavaScript code in Visual Studio Code, including how to install plugins, select different JS build targets, debug your scripts locally or remotely, and much more!

How To Run JavaScript Code In Visual Studio Code

  • Install a Plugin First, we need to install a plugin. In VS Code, open the Extensions view by clicking on the Extensions icon in the Sidebar (or Command Palette) and search for “Run Selection” (or use this direct link ).
  • Select Target When you select a script file, you can run it by selecting the Run Selection option from the context menu. But if you want your script to run automatically when you create a new file, select “Always Run Selection” instead.
  • Set up Custom Build Targets Once you’ve installed the “Run Selection” extension, click on its icon in the Status Bar (or press F1) to change your current target type. By default, it’s set up for NodeJS but we’ll switch it over to TypeScript instead:
  • Add TypeScript as a Target Because TypeScript is a superset of JavaScript, it can be used in place of the default JavaScript target. To add TypeScript support, click on the “Add Configuration” button and select “TypeScript”.
  • Configure the TypeScript Target If you’ve already installed the TypeScript extension, you can skip this step. Otherwise, install it by searching for it in the Extensions view (or using this direct link ). Once installed, click on its icon to configure your new target:
  • Select Target When you select a file that contains TypeScript code, you’ll see two options: “Run Selection” and “Debug”. Both will either run or debug your script depending on which option is selected. The difference between them is that “Run Selection” will run your script with any build targets (like NodeJS) that are set up while “Debug” will only use the TypeScript target that you configured above.

Benefit Of Use “Visual Studio Code”

  • Visual Studio Code is free
  • It can be used on Windows, Mac or Linux
  • It’s open source and extensible
  • You can use any text editor for it (VS Code can be used as an IDE or a simple text editor)
  • It is hosted on GitHub
  • It has a large and growing community of users and developers
  • It comes with built-in support for many languages and is easily extendable
  • You can run HTML, CSS and JavaScript code in the browser or in the editor directly with a single click
  • It has a “GitHub Pull Request” feature that allows you to comment on PRs before merging them
  • It has a built-in terminal for running commands from your computer’s command line
  • It supports “IntelliSense” for auto-completion and navigation
  • It has built-in support for debugging most languages and can run them directly in the editor or in your browser
  • It has built-in support for Git and other source code management systems
  • It has a built-in markdown previewer that lets you preview your markdown files without ever leaving the editor
  • It supports many popular extensions
  • It has a built-in extension manager that makes it easy to find and install new extensions
  • It has a built-in terminal emulator that allows you to run commands from your computer’s command line
  • It is integrated with “GitHub” and “Bitbucket” for easy source control management
  • You can easily customize the editor with the “Settings” menu or by writing your own settings files (if you want)
  • You can quickly find out how to do something in VS Code by typing “?” in the editor and then pressing the “Tab” key

Disadvantage Of Use “Visual Studio Code”

  • It can be used only on Windows, Mac or Linux
  • It’s not open source and extensible
  • You can’t use any text editor for it (VS Code can be used as an IDE or a simple text editor)
  • It has a large and growing community of users and developers but it is not as large as that of Visual Studio
  • It has a “GitHub Pull Request” feature that allows you to comment on PRs before merging them
  • It has a built-in terminal for running commands from your computer’s command line but it does not have an integrated terminal emulator for running commands directly in the editor

Benefit Of Use “JavaScript Code”

  • It is free to use
  • It can easily be installed in any web server
  • You can use it in any operating system (Windows, Linux, Mac)
  • You can run it on Windows, Linux, Mac and even Android devices
  • It is easy to learn because of its simplicity
  • The code editor is lightweight and fast compared to other editors
  • The code editor has a built-in markdown previewer that lets you preview your markdown files without ever leaving the editor
  • You can run your code on any web server using the built-in web server
  • It supports many languages (including JavaScript, HTML, and CSS)
  • The code editor is cross-platform
  • You can easily share your code with others without having to worry about them having to install Visual Studio or another IDE
  • It is easy to extend (for example, you can create extensions that allow you to add intelligence support)
  • You can create a code editor that is different from Visual Studio
  • You can easily compile your code using the built-in compiler
  •  It is easy to debug your code in the editor (for example, you can use breakpoints)

Disadvantage of use “JavaScript Code”

  • You must install Visual Studio if you want to use it
  • It is not free to use
  • It is limited to web applications (you cannot create desktop applications with it)
  • It does not support C# and C++ (however, there are third-party extensions that provide this)
  • It only supports JavaScript
  • You cannot use the editor on Windows, Linux, Mac or Android devices

Conclusion

In conclusion, it is clear that Visual Studio is the best IDE for JavaScript development. However, if you do not want to install Visual Studio and you are not a programmer, then NodeJS Code.io is the best code editor that you can use to develop JavaScript applications. However, if you are a programmer who wants to create web apps, then you should use Visual Studio Code or Atom.

FAQ’S

Do I have to install Visual Studio if I want to use it?

No, you do not have to. You can use NodeJS Code.io to write JavaScript code.

Can I write C++ and C# code with Visual Studio Code?

Yes, you can do that too. However, there are third-party extensions that provide this functionality.

What is the difference between Visual Studio Code and Atom?

Visual Studio Code is a cross-platform code editor that works on Linux, Mac, Windows and Android. Atom is a text editor that works on Linux, Mac and Windows.

In which IDE should I use NodeJS Code?

You should use NodeJS Code in conjunction with Visual Studio Code or Atom.

You may also like

conceivablytech Logo.

Conceivably Tech is a blog that provides tech tips and tricks to make your life easier. From simple solutions to complex problems, our team of experts have you covered. We believe in making technology work for you, so you can focus on what’s important. Our mission is to provide easy-to-follow tech advice that makes a real difference in people’s lives. Join the conversation and let us help you get the most out of your technology!

Subscribe

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

© 2022 Conceivably Tech | All Rights Reserved |