What is JavaScript?

Article

JavaScript is a lightweight, interpreted programming language with first-class functions. It is the only programming language that runs natively in all major web browsers, making it the language of the web. JavaScript adds interactivity, animations, and dynamic behaviour to HTML pages. Thanks to Node.js, it also runs on servers, making it the only language that covers both front-end and back-end development.

Need to format or beautify a JavaScript file?

Open JavaScript Formatter →

History

JavaScript was created by Brendan Eich at Netscape in just 10 days in May 1995. It was originally called Mocha, then LiveScript, before being renamed JavaScript — a marketing decision to capitalise on the popularity of Sun's Java language. Despite the name similarity, the two languages are unrelated. JavaScript was standardised as ECMAScript (ES) by Ecma International in 1997. Major milestones include ES5 (2009), ES6/ES2015 (2015 — the biggest update in language history), and annual releases from ES2016 onwards.

Basic Syntax

JavaScript is dynamically typed: variables can hold any type of value and types are checked at runtime. Modern JavaScript uses let and const for variable declarations. Functions are first-class values and can be assigned to variables, passed as arguments, and returned from other functions.

// Variables
const name = "Alice";
let age = 30;

// Function
function greet(person) {
  return `Hello, ${person}!`;
}

// Arrow function
const square = (n) => n * n;

// Array methods
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);   // [2, 4, 6, 8, 10]
const evens   = numbers.filter(n => n % 2 === 0); // [2, 4]

// Async / Await
async function fetchUser(id) {
  const response = await fetch(`/api/users/${id}`);
  const data = await response.json();
  return data;
}

Data Types

JavaScript has eight data types — seven primitives and one object type:

Core Concepts

Common Use Cases

JavaScript vs Java

Despite the similar name, JavaScript and Java are completely different languages:

JavaScript vs TypeScript

TypeScript is a superset of JavaScript developed by Microsoft that compiles to plain JavaScript:

Rules to Remember

Frequently Asked Questions

What is JavaScript?

JavaScript is a lightweight, interpreted programming language with first-class functions. It is the only programming language that runs natively in web browsers and is used to add interactivity, animations, and dynamic behaviour to web pages. It can also run on servers via Node.js.

What is JavaScript used for?

JavaScript is used for interactive web pages (form validation, animations, DOM manipulation), single-page applications (React, Vue, Angular), server-side development (Node.js), mobile apps (React Native), desktop apps (Electron), and browser extensions.

Is JavaScript the same as Java?

No. JavaScript and Java are completely different languages that share only a similar name. Java is a compiled, statically typed, object-oriented language. JavaScript is interpreted, dynamically typed, and was originally designed for browser scripting.

What is the difference between JavaScript and TypeScript?

TypeScript is a superset of JavaScript developed by Microsoft that adds optional static typing. TypeScript code compiles to plain JavaScript. All JavaScript code is valid TypeScript, but TypeScript adds type annotations, interfaces and generics that help catch bugs at compile time.

Is JavaScript front-end or back-end?

Both. JavaScript originally ran only in browsers (front-end). With Node.js (2009), JavaScript can now also run on servers (back-end). This makes JavaScript the only language that can be used for both front-end and back-end development.

Is JavaScript easy to learn?

JavaScript has a relatively low barrier to entry — you only need a browser to start. Basic concepts like variables, loops, and functions are straightforward. However, async programming, the event loop, prototypal inheritance, and framework ecosystems take time to master.

Related Articles

Sources