Skip to content

JavaScript Complete Beginner to Advanced: Need, Origin & Node.js Setup

ЁЯЪА JavaScript Complete Beginner to Advanced: Need, Origin & Node.js Setup

This is the first lecture in a comprehensive JavaScript series that promises to take you from absolute beginner to an advanced level, using a first principles thinking approach rather than rote memorization. The goal is to train you to think like a senior engineer.

ЁЯза Why Was JavaScript Created When C++ and Java Existed?

The core of the lecture answers a critical question: Why invent a new language when powerful languages like C++ and Java were already available?

Reason 1: Ease of Learning for Web Designers

  • In the mid-1990s, web developers were primarily HTML and CSS designers who were not professional programmers.
  • C++ required complex setup (e.g., #include <iostream>, using namespace std;) and had strict syntax, making it intimidating. For a gentler introduction to front-end development, consider the Frontend Web Development Masterclass: HTML, CSS, and JavaScript for Beginners.
  • JavaScript was designed with a simple, forgiving syntax that is much easier to learn, similar to HTML.
    console.log("Hello World"); // Simple, runs immediately
    

Reason 2: Critical Security Issues (The "Security Nightmare")

  • C++ is a low-level language that can directly access system memory and the hard drive. A C++ program running in a browser could:
    • Read your private files.
    • Access your camera or microphone without permission.
    • Even format your hard drive.
  • JavaScript is a high-level, sandboxed language. It cannot directly access your system's files or memory. It can only manipulate the HTML and CSS of the web page. For access to hardware (like a microphone), it must explicitly ask the user for permission.

Reason 3: System Constraints & Lightweight Requirements

  • In 1995, computers had very limited resources (e.g., 4-8 MB RAM, 200 MB hard drives).
  • Running C++ in the browser would require a compiler on the user's machine, which is heavy and resource-intensive.
  • JavaScript is lightweight and designed to run quickly within the browser without a separate compilation step for the user.

Reason 4: Automatic Garbage Collection

  • In C++, the programmer must manually allocate (new) and deallocate (delete) memory. Forgetting to free memory leads to crashes.
  • JavaScript has a Garbage Collector that automatically frees up memory when it's no longer needed, making it much safer and easier to manage.

тЪЩя╕П How Does JavaScript Run in the Browser?

Every browser has a JavaScript Engine that interprets your code. The most famous one is Google Chrome's V8 Engine.

  • The V8 Engine is NOT magic. It is a program written in C++.
  • How it works: The V8 Engine's code is compiled down to machine code (binary). Your computer's processor can run machine code directly.
  • This machine code takes your JavaScript code as input and executes it line-by-line, producing the output. This is called an Interpreter.
  • Platform Dependency: The V8 Engine must be compiled into machine code for a specific operating system (Windows, macOS, Linux) and architecture (32-bit, 64-bit). This is why you need to download the correct version for your system.

ЁЯТ╗ Running JavaScript Outside the Browser with Node.js

  • Before Node.js, JavaScript could only run inside a browser.
  • Node.js is a JavaScript Runtime Environment built on Chrome's V8 Engine.
  • It essentially took the V8 engine out of the browser and added extra functionalities (like file system access), allowing JavaScript to run on servers (back-end) and on your local computer.
  • This makes JavaScript a full-stack language, allowing developers to use one language for both front-end and back-end development.

ЁЯЫая╕П Setting Up Node.js (Step-by-Step)

  1. Go to the official Node.js website (nodejs.org).
  2. Download the LTS (Long Term Support) version for your operating system.
  3. Run the installer. You will be asked to agree to the license and may need to enter your system password.
  4. Verification: Open your terminal or command prompt and run:
    node -v
    
    This will print the installed Node.js version (e.g., v22.x.x).

ЁЯзк Your First JavaScript Code

  1. Create a file named index.js.
  2. In VS Code, use Open in Integrated Terminal.
  3. Write your code:
    console.log("Strike is coming");
    
  4. Run the file using the command:
    node index.js
    
    The output will be: Strike is coming

ЁЯУЕ Preview of Next Lecture: Variables & Data Types

The next lecture will cover:

  • Variables: What they are and how to declare them using let.
  • Data Types: How different data (numbers, strings) is stored internally.
  • A deeper exploration of JavaScript's internal workings.

ЁЯОп Key Takeaways & First Principles Thinking

  • Don't just memorize syntax; understand the why behind it. This first-principles approach is echoed in Understanding My Coding Journey: From Visual Basic to Object-Oriented Programming, which shares a developer's personal path from basics to advanced concepts.
  • JavaScript was created to be easy, secure, and lightweight for the web of 1995.
  • The V8 Engine is a C++ program that interprets JavaScript.
  • Node.js extends JavaScript's power to run anywhere, not just the browser.