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 It 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
Loading code...Frequently Asked Questions
What is the difference between JavaScript and Java?
Despite similar names, JavaScript and Java are completely different languages. Java is a statically-typed, compiled language primarily used for enterprise applications and Android development. JavaScript is a dynamically-typed, interpreted language designed for web browsers. The naming similarity was a marketing decision by Netscape in 1995.
What is the difference between let, const, and var in JavaScript?
var is function-scoped and can be redeclared, which can lead to bugs. let is block-scoped and can be reassigned but not redeclared in the same scope. const is also block-scoped but cannot be reassigned after initialization. Modern JavaScript recommends using const by default, and let when reassignment is needed.
What is the difference between == and === in JavaScript?
== (loose equality) compares values after type coercion, so '5' == 5 is true. === (strict equality) compares both value and type without coercion, so '5' === 5 is false. It's generally recommended to use === to avoid unexpected type coercion bugs.
What is a closure in JavaScript?
A closure is a function that retains access to variables from its outer (enclosing) scope even after that outer function has returned. Closures enable data privacy, function factories, and callbacks. For example, an inner function can remember and access variables defined in its parent function.
What is the difference between null and undefined in JavaScript?
undefined means a variable has been declared but not assigned a value, or a function returns no value. null is an intentional assignment indicating 'no value' or 'empty'. typeof undefined returns 'undefined', while typeof null returns 'object' (a historical bug). Use null when you want to explicitly indicate absence of value.