Introduction to JavaScript

📚 Lesson 1 of 40  •  ⏱ 8 min read  •  Beginner

What is JavaScript?

JavaScript (JS) is the programming language of the web. While HTML gives structure and CSS gives style, JavaScript makes pages interactive:

Where to Write JavaScript

HTML
<!-- 1. External file (best practice) -->
<script src="main.js" defer></script>
<!-- Put this in <head>. "defer" makes it load after HTML -->

<!-- 2. Inline (for small scripts) -->
<script>
  console.log("Hello World");
</script>

<!-- Place <script> just before </body> if not using defer -->

Your First JavaScript

JavaScript
// This is a single-line comment
/* This is a multi-line
   comment */

// Print to browser console (F12 → Console tab)
console.log("Hello, World!");
console.log(42);
console.log(true);

// Show a popup
alert("Hello from JavaScript!");

// Ask the user a question
let name = prompt("What is your name?");
console.log("Hello, " + name);

Using the Browser Console

The browser console is your best friend for learning and debugging JavaScript:

  1. Open Chrome or Firefox
  2. Press F12 (or Right-click → Inspect)
  3. Click the Console tab
  4. Type any JavaScript and press Enter — it runs immediately!
Console — try these
2 + 2                  // Output: 4
"Hello" + " World"    // Output: "Hello World"
Math.max(3, 7, 1)     // Output: 7
new Date()            // Output: current date/time

JavaScript in the Anna University Curriculum

JavaScript is covered in the Web Technology subject (typically Semester 5 for CSE/IT). Topics include DOM manipulation, AJAX, JSON and React basics. This course covers all of that and more.