What is JavaScript?

JavaScript

JavaScript is a programming language that originated in 1995 as a simple client-side scripting language for Netscape Navigator browser but metamorphosed into one of the underpinning forces behind World Wide Web (alongside HTML and CSS), and had its usage extended to server-side programming (primarily due to the origination of the Node.js server-side runtime environment). Although JavaScript started as one company endeavor, it is now used universally with most major browsers featuring JavaScript runtime environments, and Ecma International standardizing its versions.

Introduction

From the technological perspective, JavaScript is a programming language that:

JavaScript Origins

In 1993, the NCSA Mosaic browser, developed at the National Center for Supercomputing Applications at the University of Illinois, was released. It became the first publicly used browser available on the Windows operating system that integrated text and graphics. It supported multiple Internet protocols such as Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP) but it did not feature a scripting language similar to JavaScript. Microsoft licensed one of the versions of Mosaic in 1995 and built Internet Explorer on top of that.

In 1994, the lead developers of Mosaic founded Netscape Navigator browser which quickly became prevalent. In 1995, it was decided to add a scripting language to Netscape Navigator to allow for dynamic modifications of documents. One of the ideas was to use the Java language in collaboration with Sun Microsystems, the other was to embed the Schema language. However, finally, it was decided to devise a new one. The task was entrusted to Brendan Eich.

The newly devised scripting language was called LiveScipt in one of the beta iterations of the Netscape browser but the name was changed to JavaScript for the official release. The first official version of the Netscape Navigator browser that featured JavaScript was released in December 1995.

Microsoft also released its browser, Internet Explorer, in 1995. Internet Explorer was equipped with JScript which interpreter was reverse-engineered JavaScript interpreter from Netscape Navigator. Thus, the march to the prevalence of JavaScript as the main scripting language of the web has begun.

JavaScript Ecma Standardization

Approximately one year after its official debut Netscape submitted JavaScript to Ecma International for standardization.

The first version of JavaScript standardized by Ecma International was called ECMAScript (ES1) and released in 1997.

The second standardized JavaScript version called ECMAScript 2 (ES2) was released in 1998.

The third standardized JavaScript version called ECMAScript 3 (ES3) was released in 1999.

In the beginning, Microsoft and its browser Internet Explorer adhered to the Ecma standardization but later its collaboration stopped. Given the prevailing market share of Internet Explorer at the time, this caused the fourth version of the standardized JavaScript version (ES4) to never be released.

Microsoft's dominance in the browser market of the early 2000s was broken due to the release in 2004 of Netscape Navigator successor, Firefox, and the release in 2008 of Google Chrome. Google Chrome's featured fast JavaScript runtime engine - V8. Both browsers bit huge chunks from the browser market. The need for standardization arose anew.

The joint effort of interested parties and Ecma International led to the release of epochal JavaScript versions, namely ECMAScript 5 (ES5) in 2009 and ECMAScript 6 (ES6) in 2015.

The subsequent versions of JavaScript are denoted by their release year rather than a number. Therefore, after ES6, the ECMAScript releases were called ECMAScript 2016, ECMAScript 2017, ECMAScript 2018, ECMAScript 2019, etc. Although, their numeric names, ES7, ES8, ES9, ES10, etc. are also sometimes used.

JavaScript as a Client-Side Programming Language

As outlined above, JavaScript originated as a user-agent (browser) built-in programming language.

Today, JavaScript is the primary and the most pervasive client-side language of the World Wide Web.

On the client-side JavaScript can be used among others to:

  • manipulate Document Object Model, i.e. to add, change, and remove elements of documents in browsers, and

  • fetch data from remote hosts.

To streamline JavaScript development on the client-side many libraries and frameworks were developed. Currently, amongst the most popular are:

JavaScript as a Server-Side Programming Language

Although JavaScript began its life as a client-side (browser embedded) scripting language it is also now vastly used as a server-side language.

The popularity of JavaScript as a server-side programming language began with the creation of Node.js in 2009 by Ryan Dahl.

Node.js uses JavaScript V8 engine developed by Google under the hood. Node.js features event loop and I/O APIs.

The default package manager for Node.js is called npm.

There are many server-side JavaScript libraries and frameworks that facilitate development. Some of the notable are:

  • Express created by TJ Holowaychuk,

  • Next.js created by Guillermo Rauch and developed by Vercel, and

  • NestJS created by Kamil Mysliwiec.

JavaScript as a High-Level Programming Language

JavaScript is a high-level programming language.

A high-level programming language

A high-level programming language is a programming language that does not require a direct management of computer hardware (e.g. a memory management) but is capable of abstracting away such control when needed through its built-in underlying procedures and therefore allows for easier and faster program development.

JavaScript as a Just-In-Time Compiled Programming Language

JavaScript is a just-in-time compiled programming language.

A just-in-time compiled programming language

A just-in-time compiled programming language is a programming language in which source code is being compiled to machine code in parts during those parts run-time execution as opposed to ahead-of-time complete source-code compilation. Generally, the just-in-time compilation combines the speed of ahead-of-time compilation and the flexibility of interpretation.

JavaScript as a Weakly-Typed Programming Language

JavaScript is often referred to as a weakly typed programming language.

However, there are many different definitions of what a weakly typed programming language actually is.

When referring to JavaScript as a weakly typed language it is often understood as JavaScript capabilities of implicit casting of its values in some of its built-in operators.

For example, when comparing two values of different data types using abstract comparison == operator those values are implicitly cast to congruent data types before actual comparison.

1 == "1" // => true

Another example is an implicit casting of both operands to strings - when any of the operands is not a number - by the binary + operator.

1 + "1" // => "11"

Yet another example is an implicit casting of both operands to numbers - when any of the operands is not a number - by the binary - operator.

1 - "1" // => 0

JavaScript as a Dynamically Typed Programming Language

JavaScript is a dynamically typed programming language.

A dynamically-typed programming language

A dynamically-typed programming language is a programming language in which an identifier (such as a variable) current data type is inferred by the interpreter during runtime and is allowed to dynamically change during that runtime as opposed to being statically set (explicitly or implicitly) before runtime compilation.

// JavaScript (dynamic typing)
let foo = 42
foo = "forty-two" // Re-assignment from number to string allowed.
// TypeScript (static typing)
let foo = 42 // foo data type implicitly statically set to type 'number'
foo = "forty-two" // Type 'string' is not assignable to type 'number'.

JavaScript as a Prototype-Based Programming Language

Since its beginning in 1995, JavaScript has been a prototype-based programming language.

A prototype-based programming language

A prototype-based programming language is an object-oriented programming language in which an object can inherit properties of another object through a) setting that object as a prototype and delegating property calls to that other object (delegation-based prototyping), or b) copying that other object properties (concatenative prototyping), and as opposed to inheriting properties through an instantiation of a specially dedicated construct called a class.

JavaScript implements delegation-based prototyping.

const human = { profession: 'working', order: 'Primates' }
const student = { name: 'Dave', profession: 'studying' }

Object.setPrototypeOf(student, human)

student.name // => 'Dave'
student.profession // => 'studying'
student.order // => 'Primates'

Further reading at Prototypal Inheritance in JavaScript.

JavaScript as a Class-Based Programming Language

Since ECMAScript 2015 (ES6), JavaScript is a class-based programming language.

A class-based programming language

A class-based programming language is an object-oriented programming language in which an object can inherit properties from a specially dedicated for inheritance construct called a class (which might and might not be an object itself), and as opposed to inheriting properties from a non-class object.

class Dog {
  constructor(name) {
    this.name = name
  }

  bark() {
    console.log('Woof!')
  }
}

const pluto = new Dog('Pluto')

pluto.name // => 'Pluto'
pluto.bark() // 'Woof!'

Further reading at Class-Based Inheritance in JavaScript.

JavaScript as an Object-Oriented Programming Language

JavaScript is an object-oriented programming language.

An object-oriented programming language

An object-oriented programming language is a programming language which features objects which are programming constructs a) with unique identity, b) encapsulating data pieces (often called state) and procedures (often called methods), jointly referred to as properties, and c) which can inherit the said properties from specially dedicated for inheritance constructs called classes (which might and might not be objects themselves) and/or from other non-class objects, which are then called prototypes.

const pirate = {
  name: 'Hook',
  battleCry: function() { console.log('Huzzah!') }
}

pirate.name // => 'Hook'
pirate.battleCry() // 'Huzzah!'

However, JavaScript is not a purely object-oriented programming language (like for example Ruby) as it still features primitives (such as numbers, strings, and booleans) which have no state, nor methods associated with them.

JavaScript as a Functional Programming Language

JavaScript is a functional programming language.

A functional programming language

A functional programming language is a programming language in which functions can be bound to identifiers, such as among others variables, passed as other function arguments, and returned as values from other functions.

When functions have capabilities of being bound to identifiers, passed as arguments, and being other functions return values, they are often referred to as the first-class citizens.

JavaScript can make use of two functional programming paradigms:

  • an impure functional programming, and

  • a pure functional programming.

An impure functional programming is a functional programming:

  • which can rely on out-of-scope values and therefore can return different values when provided the same arguments, and

  • in which function execution is allowed to have side effects such as out-of-scope value modification.

A pure functional programming is a functional programming:

  • which cannot rely on out-of-scope values and therefore always returns the same value when provided the same arguments, and

  • in which function execution is not allowed to have side effects such as out-of-scope value modification.

JavaScript as an Imperative Programming Language

JavaScript can be used as an imperative programming language.

An imperative programming language

An imperative programming language is a programming language which uses a sequence of commands (in Latin imperare means command), aka statements, each of which denotes a specific action to be carried out that can directly change a given program's process state.

let age = 42
const feelingYoung = true

if (feelingYoung) {
  age = age / 2
}

JavaScript as an Event Driven Programming Language

JavaScript can be used as an event-driven programming language.

An event-driven programming language

An event-driven programming language is a programming language in which the control flow of a program's process is determined by events triggered by a) the process itself, b) other process messages, and c) user interactions (key presses, mouse clicks, mouse scrolls, etc.).

// Logs "window clicked" every time the browser window is clicked.
const logWindowClicked = () => console.log('window clicked!')
window.addEventListener('click', logWindowClicked, false)