Where should i run javascript?

In order to follow along with this course, you need to know how and where you run your JavaScript code. You have several options to run your first hello world programming:

Open your editor and create a file named index.js.

file_type_js index.js

console.log('hello world')

How to Run JavaScript from the Command Line

Running a JS program from the command line is handled by NodeJS. Start by installing NodeJS on local machine if necessary.

  1. Install Node.js

Now simply open the command line in the same directory as the index.js script you created (VS Code will do this automatically with the integrated terminal).

command line

node .

// or 

node index.js

How to Run JavaScript from the Browser

When people think of “JavaScript”, they most often think of a web browser. You can run code in the browser by creating an HTML file that references the script. In our case, we used the defer option, which will execute the JS after the HTML file is finished loading.

Run a script from an HTML file

file_type_html index.html

<html>
    <head>
        <script defer src="./index.js">script>
    head>
html>

Now simply open this HTML file on your local machine and open the developer console (next step) to see the output.

Inspect the Browser Console

In Chrome, you can open the developer console with Ctrl+Shift+J (Windows) or Ctrl+Option+J (Mac), or manually from the settings menu by selecting More Tools -> Developer Tools. The console allows you to run code in the browser, similar to how

Where should i run javascript?

Output of the browser console in Chrome

Run JavaScript with a Framework

It is worth mentioning that frameworks like React, Angular, Svelte, etc will take care of the building & running of your app automatically and provide framework-specific tooling and steps for running code. In the real world, you are more likely to use the tooling provided by the framework to run your code, as opposed to the basic methods shown in this couse.

Run JavaScript in a Sandbox

This course uses StackBlitz to run JS code examples in an isolated sandbox in the browser. This is a great option for sharing quick demos and issue reproductions 💡.

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    You can run your JavaScript file from your terminal only if you have installed Node.Js in your system. Install Node.js from Steps to install Node.js.

    If you have already installed it, then simply open the terminal and type “node .js”.

    Example 1: Create a JavaScript file. Name this file as New.js

    javascript

    const add = (a, b) => {

        return a + b

    }

    console.log(add(4, 6))

    Output:

    10

    Steps :

    1. Open Terminal or Command Prompt.
    2. Set Path to where New.js is located (using cd).
    3. Type “node New.js” and press ENTER.

    Example 2: Create a JavaScript File Name this file as New2.js

    javascript

    const sub = (a, b) => {

        return a - b

    }

    console.log(sub(6, 2))

    Output:

    4

    JavaScript is best known for web page development but is also used in various non-browser environments. You can learn about JavaScript from the ground up by following JavaScript Tutorial and JavaScript Examples.

    What should I install to run JavaScript program?

    Running a JS program from the command line is handled by NodeJS. Start by installing NodeJS on local machine if necessary. Now simply open the command line in the same directory as the index. js script you created (VS Code will do this automatically with the integrated terminal).

    What software can run JavaScript?

    Most likely, you'll find your JavaScript editor of choice in Sublime Text, Visual Studio Code, or Brackets. But several other tools—Atom, BBEdit, Notepad++, Emacs, and Vim—all have something to recommend them. Depending on the task at hand, you might find any one of them handy to have around.

    Can JavaScript run on any platform?

    A JavaScript application runs on every device, whereas a desktop or mobile application runs only on the application it is targeted to (Windows, Mac OSX, Linux, iPhone, Android). This allows you to write cross-platform apps in a really easy way. JavaScript's role has also expanded significantly. Platforms such as Node.

    How do I run a .JS file?

    You can run your JavaScript file from your terminal only if you have installed Node. Js in your system. Install Node..
    Open Terminal or Command Prompt..
    Set Path to where New. js is located (using cd)..
    Type “node New. js” and press ENTER..