What is JavaScript & How It Works
JavaScript is the programming language of the web. It makes websites interactive — buttons, forms, animations, and dynamic content. JavaScript runs directly in the browser and on servers (Node.js), making it the most versatile language for web development.
What is JavaScript?
JavaScript (JS) is a lightweight, interpreted programming language created in 1995. While HTML provides structure and CSS provides styling, JavaScript adds interactivity and logic. Every modern website uses JavaScript. It runs in the browser without any installation — open DevTools (F12) and start coding immediately.
HTML provides structure, CSS adds styling, JavaScript adds interactivity
What JavaScript Can Do
- Change HTML content dynamically — show/hide elements, update text, modify styles
- Respond to user actions — clicks, keyboard input, mouse movements, form submissions
- Validate form inputs before sending to the server — instant feedback without page reload
- Fetch data from APIs — load content, display live data, communicate with servers
- Create animations and visual effects — smooth transitions, scroll effects, interactive UI
- Build complete web applications — React, Vue, Angular are all JavaScript frameworks
- Run on servers with Node.js — one language for both frontend and backend
Your First JavaScript
// JavaScript runs in the browser console (press F12)
console.log("Hello, World!");
console.log("Welcome to JavaScript!");
// JavaScript can do math
console.log(10 + 5); // 15
console.log(100 * 2); // 200
// JavaScript can work with text
console.log("My name is " + "Alice");
// JavaScript can make decisions
if (10 > 5) {
console.log("10 is greater than 5!");
}Try It Yourself: Hello World
Tip
Tip
Open your browser console right now (F12 → Console tab) and type code directly — it's the fastest way to practice. Every modern browser has a built-in JavaScript playground with zero setup.
Common Mistake
Warning
Don't confuse JavaScript with Java — they are completely different languages with different use cases. JavaScript runs in browsers and Node.js; Java is a compiled language for enterprise and Android apps.
Practice Task
Note
Open DevTools (F12 → Console) and try these exercises: (1) Type console.log('Your Name') and press Enter. (2) Calculate your birth year: console.log(2026 - yourAge). (3) Combine text: console.log('Hello ' + 'World').
Quick Quiz
Key Takeaways
- JavaScript is the programming language of the web.
- Change HTML content dynamically — show/hide elements, update text, modify styles
- Respond to user actions — clicks, keyboard input, mouse movements, form submissions
- Validate form inputs before sending to the server — instant feedback without page reload