TutorialsJavaScriptIntroduction to JavaScript
JavaScript

Introduction to JavaScript

JavaScript (JS) is the programming language of the web. While HTML provides structure and CSS provides style, JavaScript adds behavior — making pages interactive, dynamic, and powerful.

JavaScript runs directly in the browser without any setup required.

// Single-line comment
/* Multi-line comment */

// Output to the console (press F12 → Console tab to see it)
console.log("Hello, World!");
console.log(42);
console.log(true);
console.log([1, 2, 3]);

// Basic arithmetic operators
console.log(2 + 3);    // 5  (addition)
console.log(10 - 4);   // 6  (subtraction)
console.log(3 * 4);    // 12 (multiplication)
console.log(15 / 4);   // 3.75 (division)
console.log(15 % 4);   // 3  (remainder/modulo)
console.log(2 ** 10);  // 1024 (exponentiation)

// Comparison operators (return true or false)
console.log(5 > 3);    // true
console.log(5 === "5");// false (strict equality: different types)
console.log(5 == "5"); // true (loose equality: coerces types — avoid!)
💡

Open the browser console now. Press F12 (or Cmd+Option+I on Mac), click the Console tab, and type any JavaScript expression. This is the fastest way to learn — experiment freely!

How to add JavaScript to a page:

<!-- At the end of <body> — ensures HTML is loaded first -->
<body>
  <h1>My Page</h1>

  <!-- Inline script (for small experiments) -->
  <script>
    console.log("Page loaded!");
  </script>

  <!-- External script file (recommended for real projects) -->
  <script src="app.js" defer></script>
</body>

Watch & Learn

A recommended video to watch alongside this chapter.

More “Introduction to JavaScript” videos on YouTube