How to Start Coding in JavaScript for Beginners

Start writing JavaScript today with zero setup. Learn three ways to run your first code: browser console, HTML script tag, and a code editor with a live preview.

6 min read

You can start coding JavaScript right now, on the same computer you are using to read this article. You do not need to install anything, create an account, or spend money. Every web browser already has a JavaScript engine built in.

Here are three ways to write your first JavaScript code, from fastest to most powerful.

Method 1: The Browser Console (30 Seconds)

The console is the fastest way to write JavaScript. It runs code immediately and shows results on the spot.

Open your browser

Open Chrome, Firefox, or Edge.

Open developer tools

Right-click anywhere on the page and select Inspect (or press Ctrl+Shift+I on Windows/Linux, Cmd+Option+I on Mac).

Click the Console tab

This is where you type and run JavaScript.

Type a line of JavaScript

Type any line and press Enter to run it.

Try these three lines one at a time. The first prints a message to the console:

javascriptjavascript
console.log("Hello, world!");

Press Enter after typing the line above, and the console prints the exact text you passed in, right below the line you typed:

texttext
Hello, world!

The second is just a math expression, with no console.log() needed. The console evaluates whatever you type and shows the result automatically:

javascriptjavascript
2 + 2

Since this line returns a value instead of explicitly printing one, the console still displays that return value directly below it, without needing console.log():

texttext
4

The third line shows a popup dialog instead of printing to the console, which is a visible way to confirm JavaScript is running on the page:

javascriptjavascript
alert("JavaScript is working!");

If you see the popup appear in your browser, JavaScript is running.

The console is perfect for testing small ideas and seeing results instantly. It is not good for saving code -- everything disappears when you close the tab.

Method 2: An HTML File with a Script Tag (2 Minutes)

To save your JavaScript and run it again later, create an HTML file.

Open a text editor

Use Notepad on Windows, TextEdit on Mac, or VS Code.

Paste the following code

Copy the HTML below into a new file.

htmlhtml
<!DOCTYPE html>
<html lang="en">
<head>
  <title>My First JavaScript</title>
</head>
<body>
  <h1>My First JavaScript Page</h1>
  <p>Open the console to see the output.</p>
</body>
</html>

Add a &lt;script&gt; block right before the closing body tag so it runs after the page content loads. Placing it here means every element above it already exists on the page:

htmlhtml
<script>
  console.log("This runs from an HTML file!");
  console.log("The time right now is: " + new Date().toLocaleTimeString());
</script>

Save the file

Save it as index.html on your desktop.

Open it in your browser

Double-click the file to open it.

Open the console

Press Ctrl+Shift+I or Cmd+Option+I to see the output.

The &lt;script&gt; tag tells the browser to run the JavaScript inside it. You can put any JavaScript between the opening and closing tags.

For larger programs, you will want to put JavaScript in a separate file:

htmlhtml
<script src="app.js"></script>

This tells the browser to load app.js from the same folder as your HTML file. The code inside it runs exactly as if it were between the script tags.

Method 3: A Code Editor with Live Preview (5 Minutes)

For serious learning, you need a proper code editor. VS Code is free and works on every platform.

Download VS Code

Install and open it

Run the installer, then launch the editor.

Create a project folder

Make a new folder for your JavaScript projects.

Create two files

Inside that folder, create index.html and app.js.

index.html:

htmlhtml
<!DOCTYPE html>
<html lang="en">
<head>
  <title>JavaScript Practice</title>
</head>
<body>
  <h1 id="heading">Click the button</h1>
  <button id="my-button">Click Me</button>
  <script src="app.js"></script>
</body>
</html>

This page links to app.js and includes a button with an id of "my-button", which the JavaScript file below will select and attach a click handler to.

app.js:

javascriptjavascript
const button = document.querySelector("#my-button");
const heading = document.querySelector("#heading");
let clickCount = 0;
 
button.addEventListener("click", () => {
  clickCount++;
  heading.textContent = `You clicked ${clickCount} time(s)`;
});

Open index.html in your browser (right-click the file in VS Code and select "Reveal in File Explorer" or "Reveal in Finder," then double-click). Click the button. Watch the heading change.

This is the setup you will use for every project going forward. An HTML file provides the structure, a JavaScript file provides the behavior, and they connect through a &lt;script&gt; tag.

Your First Real Program: A Number Guessing Game

Now that you have a working setup, here is a complete beginner program. Copy it into your app.js file. It starts by picking a random number and setting up a counter:

javascriptjavascript
const secretNumber = Math.floor(Math.random() * 10) + 1;
let attempts = 0;
 
function checkGuess() {
  const guess = Number(prompt("Guess a number between 1 and 10:"));
  attempts++;

The rest of the function compares the guess to the secret number and calls itself again if the guess was wrong:

javascriptjavascript
  if (guess === secretNumber) {
    alert(`Correct! You got it in ${attempts} attempt(s).`);
  } else if (guess < secretNumber) {
    alert("Too low. Try again.");
    checkGuess();
  } else {
    alert("Too high. Try again.");
    checkGuess();
  }
}
checkGuess();

This program uses variables, a function, a conditional, and recursion (the function calls itself until you guess correctly). That is four core JavaScript concepts in 15 lines.

What to Do Next

Here is the most effective daily routine for a beginner:

TimeActivity
5 minReview what you learned yesterday. Run the code again.
15 minLearn one new concept. Write 5-10 small examples.
5 minChange one example and see what happens. Break it on purpose.

The "break it on purpose" step is the most important. Try changing a variable name or removing a parenthesis, then see what error appears.

Reading error messages is a skill, and the only way to learn it is to trigger errors on purpose.

For a guided walkthrough of building a complete interactive page, follow the step-by-step JavaScript tutorial with real examples. To learn the two main ways to run JavaScript, in the browser and on a server, see how to run JavaScript in the browser and Node.js.

Rune AI

Rune AI

Key Insights

  • You can write JavaScript in your browser console right now with zero setup.
  • Create an HTML file, add a <script> tag, and open it in a browser for persistent code.
  • VS Code is the best free editor for writing JavaScript.
  • Start with console.log() to see output, then move to DOM manipulation.
  • Write and run code every day, even if only for 20 minutes.
RunePowered by Rune AI

Frequently Asked Questions

Do I need to install anything to start coding JavaScript?

No. Every modern web browser has a built-in JavaScript engine and console. You can write and run JavaScript right now without installing anything. For larger projects, you will eventually want a code editor like VS Code.

What is the best code editor for JavaScript?

VS Code (Visual Studio Code) is the most popular JavaScript editor. It is free, works on Windows, Mac, and Linux, and has excellent JavaScript support including IntelliSense, debugging, and a built-in terminal.

Can I learn JavaScript on my phone or tablet?

It is possible but not recommended. Mobile browsers have limited developer tools, and typing code on a touchscreen is slow and error-prone. Use a laptop or desktop computer for the best learning experience.

Conclusion

You do not need to install anything to start coding JavaScript. Open your browser console and type your first line. Create an HTML file and link a script tag. Download VS Code for a proper editing environment. The barrier to entry is zero -- the only thing you need is the willingness to start.