Special Offer Diwali Special Bundle Offer: 3 courses for ₹8,999, save ₹9,001 (50% OFF)! Limited seats available. View Bundles →
0% Completed
Tutorials / JavaScript Tutorial / Chapter 1: Getting Started & Language Basics
JAVASCRIPT ⏱ 8 min read

Introduction to JavaScript & Setup

JavaScript is the programming language that powers interactivity across the entire web. If HTML is the skeleton and CSS is the skin, JavaScript is the brain and nervous system.

What is it?

JavaScript (JS) is a high-level, interpreted or Just-In-Time (JIT) compiled, multi-paradigm programming language. Initially created to make web pages alive in browsers, it now also runs on servers via Node.js.

Why is it used?

JavaScript lets you build interactive forms, animations, dynamic live updates without page reloads, mobile apps, games, and full-stack cloud servers.

Detailed Explanation

JavaScript runs directly inside every modern web browser (Google Chrome, Firefox, Safari, Edge) via high-performance JavaScript engines like V8 (Chrome), SpiderMonkey (Firefox), and JavaScriptCore (Safari). You can write JavaScript directly in the browser DevTools Console (F12 -> Console) or include it in HTML documents using the `<script>` tag. Modern best practice is linking an external file: `<script src="script.js" defer></script>`. The `defer` attribute ensures HTML is fully parsed before the script executes.

Syntax Structure

Syntax Blueprint
// Single line comment
/* Multi-line comment */
console.log("Hello from JavaScript!");

Code Example

JAVASCRIPT Code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JS Introduction</title>
</head>
<body>
  <h1 id="greeting">Welcome to IGM Computers</h1>
  <button id="btnAction">Click Me!</button>

  <script>
    // Log output to browser developer console
    console.log("JavaScript environment initialized successfully.");

    // Add dynamic click interaction
    const btn = document.getElementById("btnAction");
    const heading = document.getElementById("greeting");

    btn.addEventListener("click", () => {
      heading.textContent = "You clicked the button! JavaScript is working.";
      heading.style.color = "#16a34a";
    });
  </script>
</body>
</html>

Explanation of the Code

1. `console.log()` writes debug messages directly into Developer Tools. 2. `document.getElementById()` finds specific elements on the page. 3. `addEventListener("click", ...)` waits for user mouse click and dynamically updates the heading text and color.

Expected Output

Clicking the button immediately changes the heading text to 'You clicked the button! JavaScript is working.' in green without reloading the page.

Real-World Application

Every dropdown menu, live search filter, modal popup, and form submission on modern websites uses JavaScript event handlers.

Common Mistakes to Avoid

• Placing `<script>` in the `<head>` without `defer` (script tries to query elements before HTML has loaded into the DOM, throwing null errors). • Confusing Java and JavaScript (they are two completely different languages with different syntax and runtimes!).

Quick Practice Challenge

Open your browser's Developer Tools (F12 or Right Click -> Inspect -> Console) and type `console.log("Hello from " + navigator.userAgent);`.

Key Takeaways

• JavaScript provides interactivity, dynamic updates, and logic to web pages. • Use `<script src="..." defer>` to load scripts safely after HTML parsing. • Use `console.log()` as your primary debugging tool in DevTools.