What is JavaScript?
JavaScript is a high-level, interpreted programming language that enables interactive web pages and is an essential part of web applications. It runs in browsers and on servers (Node.js), making it one of the most versatile programming languages.
Quick Facts
| Full Name | JavaScript Programming Language |
|---|---|
| Created | 1995 by Brendan Eich at Netscape |
| Specification | Official Specification |
How JavaScript Works
JavaScript was created by Brendan Eich at Netscape in 1995 in just 10 days. Despite its name, it has no direct relation to Java. JavaScript is a multi-paradigm language supporting event-driven, functional, and object-oriented programming styles. It is the only programming language natively supported by web browsers, making it essential for front-end development. With Node.js, JavaScript expanded to server-side development. The language is standardized as ECMAScript, with annual updates adding new features like arrow functions, async/await, and modules.
Key Characteristics
- Dynamically typed with automatic type coercion
- First-class functions and closures
- Prototype-based object orientation
- Event-driven and asynchronous programming
- Runs in browsers and on servers (Node.js)
- Standardized as ECMAScript with annual updates
Common Use Cases
- Interactive web page functionality
- Single-page applications (React, Vue, Angular)
- Server-side development (Node.js)
- Mobile app development (React Native)
- Desktop applications (Electron)
Example
// Variables and data types
const name = 'John';
let age = 30;
const isActive = true;
// Arrow function
const greet = (name) => `Hello, ${name}!`;
// Array methods
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
const sum = numbers.reduce((a, b) => a + b, 0);
// Async/await
async function fetchData(url) {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch (error) {
console.error('Error:', error);
}
}
// Classes
class User {
constructor(name, email) {
this.name = name;
this.email = email;
}
sayHello() {
return `Hi, I'm ${this.name}`;
}
}