What is JavaScript? JavaScript is a programming language that runs in web browsers. It makes web pages interactive by allowing you to respond to user actions, validate forms, animate elements, and much more.
History and Purpose of JavaScript
Created in 1995 by Brendan Eich, JavaScript was designed to make web pages interactive. Originally called Mocha, then LiveScript, it was renamed JavaScript for marketing reasons. Today, it's one of the most popular programming languages.
// Single-line comment
/* Multi-line comment
can span multiple lines
for longer explanations */
Basic Syntax Rules
Statements end with semicolons (;) - optional but recommended
JavaScript is case-sensitive (console, Console, and CONSOLE are different)
Whitespace is ignored (indentation is for readability)
Strings can use single or double quotes: 'hello' or "hello"
Variables should have meaningful names (camelCase is standard)
console.log("Hello"); // Correct
console.log('Hello'); // Also correct
console.log("Hello") // Works but missing semicolon
Variables
Variables store data values. Declare them with var, let, or const:
let name = "Alice";
let age = 28;
let isStudent = true;
console.log(name); // Output: Alice
console.log(age); // Output: 28
console.log(isStudent); // Output: true