JavaScript
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax and Types
-
Section 3: Strings and Numbers in Depth
-
Section 4: Control Flow
-
Section 5: Functions
-
Section 6: Objects and Arrays
-
Section 7: Maps, Sets, and Symbols
-
Section 8: Asynchronous JavaScript
-
Section 9: Object-Oriented and Prototypes
-
Section 10: The DOM
-
Section 11: Browser APIs
-
Section 12: Modern JavaScript (ES2015-ES2025)
-
Section 13: Functional Programming Patterns
-
Section 14: Error Handling and Debugging
-
Section 15: Testing
-
Section 16: Accessibility for JavaScript Developers
-
Section 17: Internationalization and Localization
-
Section 18: Performance
-
Section 19: Node.js Fundamentals
-
Section 20: Regular Expressions
-
Section 21: Design Patterns in JavaScript
-
Section 22: Security Basics
-
Section 23: Data Structures and Algorithms in JavaScript
-
Section 24: Practical Projects
-
Section 25: More Advanced Async Patterns
-
Section 26: More Object and Class Practice
-
Section 27: Working with Dates and Internationalization
-
Section 28: Web Components
-
Section 29: More DOM and Browser Practice
-
Section 30: Build Tooling for Vanilla JavaScript
-
Section 31: More Practice Projects
-
Section 32: Interview and Algorithm Practice
-
Section 33: Error Objects (MDN Reference)
-
Section 34: TypedArrays and Binary Data
-
Section 35: Reflection and Metaprogramming (MDN Reference)
-
Section 36: More Global Functions (MDN Reference)
142: Running JavaScript Outside the Browser
How do I actually get a .js file to run on my machine without opening a browser?
Up until now, you've probably been relying on the browser to be the "engine" that executes your code. But to run JavaScript standalone, you need a runtime environment installed on your OS. The industry standard for this is Node.js. Think of Node as taking the V8 engine—the same thing that powers Chrome—and wrapping it in a way that it can run directly on your hardware.
Once you've installed Node, you don't need an HTML file to act as a bridge. You just create a plain .js file and call it from your terminal. For example, if you have a file called process-users.js that filters a list of users, you just run:
node process-users.js
I'll show you a quick example. Instead of a generic print statement, let's imagine you're writing a script to clean up a list of messy usernames:
const users = [" alice_99 ", "BOB_smith", " Charlie_Brown "];
const cleanedUsers = users.map(u => u.trim().toLowerCase());
console.log("Cleaned User List:", cleanedUsers);
Run that with Node, and the output goes straight to your terminal. No DevTools, no console tab—just raw output in your command line.
Why am I getting "ReferenceError: document is not defined" now?
This is the first wall every developer hits when moving to the server side. You have to realize that JavaScript the language is different from the environment it lives in. The document, window, and localStorage objects aren't actually part of JavaScript; they are Web APIs provided by the browser to let you manipulate the DOM.
Node.js doesn't have a DOM because there is no visual window to manipulate. If you try to use document.querySelector() in Node, it'll crash because that object literally doesn't exist in this environment. Instead, Node gives you a different set of tools. For instance, instead of window, you have global. Instead of browser alerts, you have process.stdout.write() or simply console.log().
Can I actually interact with my computer's files using JavaScript?
Yes, and this is where it gets powerful. While the browser keeps JavaScript in a "sandbox" for security (you wouldn't want a random website deleting your photos), Node.js has full access to your system. To do this, you use built-in modules. The most common one for this is the fs (File System) module.
I use this all the time for writing quick automation scripts. Here is how you'd write a simple script to create a log file on your hard drive:
const fs = require('fs');
const logMessage = `Log entry created at: ${new Date().toLocaleString()}\n`;
// This creates a file called 'app.log' (or appends to it if it exists)
fs.appendFileSync('app.log', logMessage);
console.log("Successfully wrote to the log file!");
Just be careful. Since you're no longer in a sandbox, a fs.unlinkSync() call can permanently delete a file. You have the keys to the kingdom now, so use them wisely.
📋 Practical Task
Build a Local Project Manifest Generator
Your task is to create a Node.js script that generates a "manifest" file for a project. Instead of manually typing out a project description, you'll write a script that saves this data to a file.
- Create a file named
manifest-gen.js. - Define an object called
projectDetailscontaining aprojectName,version, andauthor. - Use the
fsmodule to convert that object into a string (hint: useJSON.stringify()with formatting) and write it to a file namedmanifest.json. - Run the script using the terminal command
node manifest-gen.jsand verify that themanifest.jsonfile was created in your folder with the correct content.
There are no comments for now.