JavaScript Tutorial · JavaScript Basics · Lesson 2 of 44
JavaScript Get Started
Run JavaScript in the browser, in a web page and with Node.js.
Three ways to run JavaScript
1. In this tutorial. Every example has a Run button and an Edit & try it yourself mode — nothing to install.
2. In a web page. Put code in a <script> tag, or in a separate .js file loaded with <script src="app.js"></script>:
<!DOCTYPE html>
<html>
<body>
<h1 id="title">Hello</h1>
<script>
document.getElementById("title").textContent = "Hello from JavaScript!";
</script>
</body>
</html>
3. With Node.js. Install Node.js from nodejs.org (choose the LTS version), save code in app.js, and run it from a terminal:
node --version
node app.js
The browser console
Open any web page, press F12 (or Cmd+Option+I on macOS) and choose Console. You can type JavaScript there and see the result immediately — perfect for quick experiments.
console.log(2 + 3);
console.log("Learning " + "JavaScript");
Output
5 Learning JavaScript
Test yourself
Which HTML tag holds JavaScript code?
<js><javascript><script><code>
Show answer
Answer: <script>