Skip to Content
Course content

2: Setting Up a Development Environment

Click on the "Edit" button in the top corner of the screen to edit your slide content.

When you're first starting out, it's tempting to keep things "simple." You might be tempted to just open a basic text editor, write a few lines of JavaScript inside a <script> tag in an HTML file, and double-click that file to open it in Chrome. I've seen plenty of people do this, and honestly, for a ten-line script, it's fine. But the moment you try to build something with actual logic—say, a function that calculates compound interest for a savings account—that "simple" setup becomes a massive bottleneck.

The "Just Put it in the HTML" Trap

The naive approach treats JavaScript as a secondary accessory to the webpage. You write your code, save the file, switch to the browser, and hit refresh. Then you realize you missed a closing parenthesis, so you switch back, fix it, save, and refresh again. It feels like a loop of wasted motion. Worse yet, if you're using a basic editor like Notepad or TextEdit, you're flying blind. You won't know you've made a syntax error until the browser's console tells you—which, let's be honest, most beginners forget to even open.

The real cost here isn't just the time spent clicking "refresh"; it's the cognitive load. When your logic and your layout are mashed together in one file, your brain is trying to track two different languages at once. It's messy, it's hard to debug, and it's not how any professional team actually works.

Moving to a Dedicated IDE

This is where you need to shift to a real Integrated Development Environment (IDE). I personally use Visual Studio Code (VS Code), and for a good reason: it does the heavy lifting for you. Instead of guessing why a variable isn't working, the IDE underlines the error in red the second you type it. It provides "IntelliSense," which is just a fancy way of saying it suggests the correct method names so you don't have to keep tabbed over to the documentation every thirty seconds.

The trade-off is a bit of upfront configuration. You have to install the software, maybe grab a few extensions, and learn a few keyboard shortcuts. It feels like "overkill" for a small project, but it's the difference between fighting your tools and having your tools work for you. I'd rather spend twenty minutes setting up my environment than spend two hours hunting for a typo in a 500-line HTML file.

Cutting Out the Middleman with Node.js

Here is the part that usually surprises people: you don't actually need a browser to run JavaScript. While JS was born in the browser, Node.js allows you to run it directly on your machine's operating system. This is a game-changer for your workflow.

Imagine you're writing that compound interest calculator. Instead of loading a whole webpage just to see if your math is correct, you can just type node calculator.js in your terminal and see the result instantly. You're testing the logic of your code in isolation, without worrying about whether a CSS margin is pushing your text off-screen. By separating your environment into a code editor for writing, a terminal for testing logic, and a browser for final rendering, you've created a professional pipeline.

// Instead of this:
// <script> console.log("Calculating..."); </script>

// Do this:
// Create a file called 'app.js'
const principal = 1000;
const rate = 0.05;
const years = 5;
const total = principal * Math.pow((1 + rate), years);

console.log(`After ${years} years, you have: $${total.toFixed(2)}`);
// Run it via terminal: node app.js



📋 Practical Task

Exercise: Building a Local VAT Tax Calculator

Your goal is to move away from the browser-based "refresh" cycle and set up a professional local workflow. Follow these requirements:

  • Install Visual Studio Code and Node.js on your machine.
  • Create a dedicated folder for this project and open that folder in VS Code.
  • Create a standalone JavaScript file named taxCalculator.js (do not use an HTML file).
  • Write a script that defines a price variable and a vatRate variable (e.g., 0.20 for 20%).
  • Calculate the total price including tax and use console.log() to print a formatted string like: "The total price including VAT is: $120.00".
  • Open the integrated terminal in VS Code (Ctrl + `) and execute your code using the command node taxCalculator.js.
  • Modify the price variable and run the command again to verify the output changes without ever opening a web browser.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.