There are several methods for running JavaScript:
-
Command Line - Various runtime systems exist that can run
.jsfiles or open an interactive shell. The most common is Node.js but smaller alternatives are RingoJS and PurpleJS as well as the more recent Deno.- Run as
> node myscript.js
- Run as
-
Within HTML - JavaScript can be included in HTML files and will be run by browsers reading the files
- Inline:
<script>alert("Hello World")</script>
- External (preferred)
<script src="./index.js"></script>
-
Browser Console - Web browsers usually provide a console (a.k.a. REPL, language shell) for running JS code. It is basically an IDE. The console environment will be set by the browser window/tab from which the console was opened.
- Chrome: Settings → More Tools → Developer Tools. You can undock the console to write code in a separate window instead of in split-screen mode.
- Safari, Firefox, etc...
-
Web App - A few online IDEs exist, such as StackBlitz, that can run code in various environments.