JavaScript
JavaScript (JS) is a programming language and core technology of the Web, alongside HTML and CSS.
≈ 6 min read
JavaScript. encyclopegia.org, snapshot enwiki-001378180047. /a/javascript
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
JavaScript (JS) is a programming language and core technology of the Web, alongside HTML and CSS. Created by Brendan Eich in 1995, it is maintained by Ecma International's TC39 technical committee, with related Web APIs maintained by W3C and WHATWG. As of 2025, JavaScript is the most widely used programming language on GitHub.
However, TypeScript, which is a version of JavaScript that is strict about types and is statically typed, overtook JavaScript on GitHub by August 2025. Web browsers have a dedicated JavaScript engine that executes the client code. These engines are also utilized in some servers and a variety of apps.
The most popular runtime system for non-browser usage is Node.js. JavaScript is a high-level, often just-in-time–compiled language that conforms to the ECMAScript standard. It has dynamic typing, prototype-based object-orientation, and first-class functions.
It is multi-paradigm, supporting event-driven, functional, and imperative programming styles. It has application programming interfaces (APIs) for working with text, dates, regular expressions, standard data structures, and the Document Object Model (DOM). The ECMAScript standard does not include any input/output (I/O), such as networking, storage, or graphics facilities.
In practice, the web browser or other runtime system provides JavaScript APIs for I/O. Although Java and JavaScript are similar in name and syntax, the two languages are distinct and differ greatly in design. In JavaScript, an object is an associative array, augmented with a prototype (see below); each key provides the name for an object property, and there are two syntactical ways to specify such a name: dot notation ( obj.x = 10 ) and bracket notation ( obj["x"] = 10 ).
A property may be added, rebound, or deleted at run-time. Most properties of an object (and any property that belongs to an object's prototype inheritance chain) can be enumerated using a for...in loop. JavaScript uses prototypes where many other object-oriented languages use classes for inheritance, but it's still possible to simulate most class-based features with the prototype system.
Additionally, ECMAScript version 6 (released June 20151) introduced the keywords class, extends and super, which serve as syntactic sugar to abstract the underlying prototypal inheritance system with a more conventional interface. Constructors are declared by specifying a method named constructor, and all classes are automatically subclasses of the base class Object, similarly to Java. class Person { constructor(name) { this.name = name; } } class Student extends Person { constructor(name, id) { super(name); this.id = id; } } const bob = new Student("Robert", 12345); console.log(bob.name); // Robert Though the underlying object mechanism is still based on prototypes, the newer syntax is similar to other object oriented languages.
Private variables are declared by prefixing the field name with a number sign (#), and polymorphism is not directly supported, although it can be emulated by manually calling different functions depending on the number and type of arguments provided. Functions double as object constructors, along with their typical role.
Prefixing a function call with new will create an instance of a prototype, inheriting properties and methods from the constructor (including properties from the Object prototype). ECMAScript 5 offers the Object.create method, allowing explicit creation of an instance without automatically inheriting from the Object prototype (older environments can assign the prototype to null ).
The constructor's prototype property determines the object used for the new object's internal prototype. New methods can be added by modifying the prototype of the function used as a constructor. // This code is completely equivalent to the previous snippet function Person(name) { this.name = name; } function Student(name, id) { Person.call(this, name); this.id = id; } var bob = new Student("Robert", 12345); console.log(bob.name); // Robert JavaScript's built-in classes, such as Array and Object , also have prototypes that can be modified.
However, it's generally considered bad practice to modify built-in objects, because third-party code may use or inherit methods and properties from these objects, and may not expect the prototype to be modified. // Declares a function-scoped variable named `x`, and implicitly assigns the // special value `undefined` to it. Variables without value are automatically // set to undefined. // var is generally considered bad practice and let and const are usually preferred. var x; // Variables can be manually set to `undefined` like so let x2 = undefined; // Declares a block-scoped variable named `y`, and implicitly sets it to // `undefined`.
The `let` keyword was introduced in ECMAScript 2015. let y; // Declares a block-scoped, un-reassignable variable named `z`, and sets it to // a string literal. The `const` keyword was also introduced in ECMAScript 2015, // and must be explicitly assigned to. // The keyword `const` means constant, hence the variable cannot be reassigned // as the value is `constant`. const z = "this value cannot be reassigned!"; // Declares a global-scoped variable and assigns 3.
This is generally considered // bad practice, and will not work if strict mode is on. t = 3; // Declares a variable named `myNumber`, and assigns a number literal (the value // `2`) to it. let myNumber = 2; // Reassigns `myNumber`, setting it to a string literal (the value `"foo"`). // JavaScript is a dynamically-typed language, so this is legal. myNumber = "foo"; Note the comments in the examples above, all of which were preceded with two forward slashes. More examples can be found at the Wikibooks page on JavaScript syntax examples.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1378180047 under CC BY-SA 4.0; modifications have been made.
References
- ↩Wikipedia “JavaScript” release date (×1) · confidence 0.95 revision URL