Before you start writing JavaScript code, you need the right tools. The good news? Everything you need is completely free and easy to set up. In this lesson, we'll get your development environment ready so you can start coding right away.
What You Need
To write and run JavaScript code effectively, you need just two things:
- A Code Editor - Where you write your code
- A Web Browser - Where you test and run your code
That's it! Let's set up each one.
Note: You probably already have a web browser (Chrome, Firefox, Safari, or Edge). We'll focus on making sure you're using it effectively for JavaScript development.
Choosing a Code Editor
While you can write JavaScript in any text editor (even Notepad), a proper code editor makes your life much easier with features like:
- Syntax highlighting: Different colors for different parts of your code
- Auto-completion: Suggestions as you type
- Error detection: Spotting mistakes before you run the code
- Debugging tools: Finding and fixing issues
Visual Studio Code (Recommended)
Visual Studio Code (VS Code) is the most popular code editor for JavaScript development, and we highly recommend it for beginners. Here's why:
- It's completely free and open-source
- Works on Windows, Mac, and Linux
- Excellent JavaScript support built-in
- Huge library of extensions
- Active community and regular updates
- Integrated terminal
- Git integration for version control
Download VS Code:
Visit https://code.visualstudio.com and download the version for your operating system.
Alternative Editors
If you prefer something different, here are other good options:
- Sublime Text: Fast and lightweight
- Atom: Highly customizable (discontinued but still usable)
- WebStorm: Powerful but paid (free trial available)
- Brackets: Good for web development
For this tutorial series, we'll use VS Code in our examples, but the concepts apply to any editor.
Installing VS Code
Windows
- Download the installer from code.visualstudio.com
- Run the downloaded .exe file
- Follow the installation wizard
- Check "Add to PATH" during installation (makes it easier to open)
- Click Install and wait for completion
Mac
- Download the .zip file from code.visualstudio.com
- Open the downloaded file
- Drag Visual Studio Code to your Applications folder
- Launch VS Code from Applications
Linux
- Download the .deb or .rpm package (depending on your distro)
- Install using your package manager or from the command line
# Ubuntu/Debian
sudo apt install ./code*.deb
# Fedora/RHEL
sudo dnf install ./code*.rpmEssential VS Code Extensions for JavaScript
Extensions add extra functionality to VS Code. Here are the must-have extensions for JavaScript development:
How to Install Extensions
- Open VS Code
- Click the Extensions icon in the sidebar (or press Ctrl+Shift+X)
- Search for the extension name
- Click Install
Recommended Extensions
1. ESLint
Identifies and fixes problems in your JavaScript code automatically.
Extension Name: ESLint
Publisher: Microsoft
2. Prettier - Code Formatter
Automatically formats your code to look clean and consistent.
Extension Name: Prettier - Code formatter
Publisher: Prettier
3. Live Server
Launches a local development server with live reload feature for testing your web pages.
Extension Name: Live Server
Publisher: Ritwick Dey
4. JavaScript (ES6) Code Snippets
Provides shortcuts for writing common JavaScript code patterns.
Extension Name: JavaScript (ES6) code snippets
Publisher: charalampos karypidis
5. Path Intellisense
Autocompletes file paths in your code.
Extension Name: Path Intellisense
Publisher: Christian Kohler
š” Pro Tip:
You don't need to install all extensions at once. Start with just Prettier and Live Server, then add others as you need them.
Configuring VS Code for JavaScript
Let's optimize VS Code for JavaScript development with some recommended settings.
Opening Settings
- Open VS Code
- Go to File ā Preferences ā Settings (or press Ctrl+, on Windows/Linux, Cmd+, on Mac)
- Search for the setting you want to change
Recommended Settings
Format On Save: Automatically format your code when you save
Search for: format on save
Check the box to enable it
Auto Save: Automatically save files as you type
Search for: auto save
Set to: afterDelay
Tab Size: Set consistent indentation
Search for: tab size
Set to: 2 or 4 (2 is more common for JavaScript)
Setting Up Your Browser
Any modern browser works for JavaScript development, but we recommend:
- Google Chrome - Most popular, excellent dev tools
- Mozilla Firefox - Great dev tools, privacy-focused
- Microsoft Edge - Built on Chromium, same tools as Chrome
Browser Developer Tools
Every modern browser includes Developer Tools (DevTools) - a powerful set of features for debugging and testing JavaScript.
Opening DevTools
- Windows/Linux: Press F12 or Ctrl+Shift+I
- Mac: Press Cmd+Option+I
- Or: Right-click on a page and select "Inspect"
Key Tabs in DevTools
Console Tab:
- Run JavaScript code directly
- See console.log() output
- View errors and warnings
Sources Tab:
- View and debug JavaScript files
- Set breakpoints
- Step through code execution
Elements Tab:
- Inspect HTML structure
- See CSS styles
- Modify page in real-time
Network Tab:
- Monitor network requests
- See API calls
- Check loading times
Using the Browser Console
The browser console is where you'll spend a lot of time testing and debugging JavaScript. Let's learn how to use it.
Running JavaScript in the Console
- Open any webpage
- Press F12 to open DevTools
- Click the Console tab
- Type JavaScript code and press Enter
š® Try This Now:
Open your browser console and try these commands:
Console Examples
Try these in your actual browser console!
console.log() to see your output in the console above.Console Methods
Beyond console.log(), there are other useful console methods:
// Regular log
console.log("Normal message");
// Warning (yellow)
console.warn("This is a warning!");
// Error (red)
console.error("This is an error!");
// Info (blue)
console.info("This is information");
// Clear console
console.clear();
// Group related logs
console.group("My Group");
console.log("Message 1");
console.log("Message 2");
console.groupEnd();Creating Your First JavaScript File
Now let's create an actual JavaScript file in VS Code.
Step 1: Create a Project Folder
- Create a new folder on your computer (e.g., "javascript-learning")
- Open VS Code
- Go to File ā Open Folder
- Select your new folder
Step 2: Create an HTML File
- Click the "New File" icon or press Ctrl+N
- Save it as index.html
- Add this basic HTML structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First JavaScript</title>
</head>
<body>
<h1>Hello, JavaScript!</h1>
<!-- Link to JavaScript file -->
<script src="script.js"></script>
</body>
</html>Step 3: Create a JavaScript File
- Create another new file
- Save it as script.js
- Add some JavaScript code:
// My first JavaScript file!
console.log("Hello from script.js!");
// Create a variable
let greeting = "Welcome to JavaScript!";
console.log(greeting);
// Do some math
let result = 10 + 5;
console.log("10 + 5 =", result);
// Show an alert
alert("Your JavaScript file is working!");Step 4: Run Your Code
There are two ways to run your code:
Method 1: Using Live Server (Recommended)
- Right-click on index.html in VS Code
- Click "Open with Live Server"
- Your browser will open automatically
- Press F12 to see console output
Method 2: Double-Click
- Double-click index.html in your file explorer
- It will open in your default browser
- Press F12 to see console output
Success! If you see your messages in the console and the alert box appears, your environment is set up correctly!
Organizing Your JavaScript Projects
As you learn, you'll create many files. Here's a simple organization structure:
javascript-learning/
āāā lesson-01/
ā āāā index.html
ā āāā script.js
āāā lesson-02/
ā āāā index.html
ā āāā script.js
āāā practice/
ā āāā experiments.js
āāā projects/
āāā calculator/
āāā index.html
āāā script.js
āāā style.cssThis keeps your learning organized and easy to navigate.
Essential VS Code Keyboard Shortcuts
Learning these shortcuts will make you much more efficient:
General
Ctrl+S- Save fileCtrl+N- New fileCtrl+W- Close fileCtrl+P- Quick file searchCtrl+Shift+P- Command palette
Editing
Ctrl+/- Toggle commentCtrl+D- Select next occurrenceAlt+Up/Down- Move line up/downShift+Alt+Down- Copy line downCtrl+Shift+K- Delete line
Navigation
Ctrl+B- Toggle sidebarCtrl+`- Toggle terminalCtrl+Tab- Switch between files
āØļø Practice Tip:
Don't try to memorize all shortcuts at once. Start with just Ctrl+S, Ctrl+/, and Ctrl+P. Learn others gradually as you code more.
Common Setup Issues & Solutions
Issue: JavaScript file not loading
Solution: Check that the script tag's src path is correct. If script.js is in the same folder as index.html, use src="script.js"
Issue: console.log() not showing anything
Solution: Make sure you've opened the browser DevTools (F12) and are looking at the Console tab, not the Elements tab.
Issue: Live Server not working
Solution: Make sure you've installed the Live Server extension. Restart VS Code after installation.
Issue: Syntax errors appearing
Solution: Check for missing semicolons, brackets, or quotes. VS Code will usually underline errors in red.
Key Takeaways
- Visual Studio Code is the recommended editor for JavaScript
- Install essential extensions: Prettier, ESLint, Live Server
- Every modern browser has DevTools (press F12 to open)
- The Console tab is where you'll test and debug code
- JavaScript files use the .js extension
- Link JavaScript files using the script tag in HTML
- console.log() is your best friend for testing code
- Organize your projects in folders from the start
What's Next?
Congratulations! Your JavaScript development environment is now set up and ready to go. You've installed VS Code, configured it for JavaScript, learned about browser DevTools, and created your first JavaScript file.
In the next lesson, we'll write your first real JavaScript program and explore the basics of how JavaScript code works. Get ready to start coding!
šÆ Action Items:
- Install VS Code if you haven't already
- Install at least the Prettier and Live Server extensions
- Create a "javascript-learning" folder on your computer
- Create your first index.html and script.js files
- Practice opening DevTools in your browser (F12)
- Run a simple console.log() to confirm everything works