Introduction to JavaScript
What is JavaScript?
JavaScript (JS) is the programming language of the web. While HTML gives structure and CSS gives style, JavaScript makes pages interactive:
- Form validation (check if email is valid before submitting)
- Dynamic content (load new posts without refreshing the page)
- Animations and effects
- Games in the browser
- Talking to servers (fetch data from APIs)
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:
- Open Chrome or Firefox
- Press F12 (or Right-click → Inspect)
- Click the Console tab
- 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.