JavaScript Host Environments

Dec 05, 2020 • ☕️ 4 min read

JavaScript was initially a browser-only scripting language. Today, JavaScript is a widely-adopted general-purpose multi-paradigm programming language that runs literally everywhere (web browsers, web servers, mobile apps, desktop apps, IoT devices).

It is very common for ECMAScript and JavaScript to be used interchangeably. ECMAScript is a specification programming language defined in the document ECMA-262. JavaScript is a dialect of ECMAScript, conforms to the ECMAScript specification while also providing additional features not described in the specification.

Host environments are platforms where JavaScript can run, each of them implements JavaScript language specification and provides additional platform specific functionality.

JavaScript language itself only defines APIs for working with text, dates, regular expressions, standard data structures. Any I/O (networking, storage, graphics, files, etc.) will be optionally provided by host environments.

Browser environments

A web browser provides a host environment for client-side computation including, for instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, input, and output.

Web browser also provides a means to attach scripting code to events such as change of focus, page and image loading, unloading, error and abort, selection, form submission, and mouse actions.

The World Wide Web Consortium (W3C) has established standards for Structural and Semantic Languages (HTML, XHTML, XML), Presentation Languages (CSS), Object Models (DOM), Scripting Languages (ECMAScript), Additional Markup Languages (MathML), commonly used to develop web pages.

All modern web browsers (Chrome, Safari, Firefox, Edge) are considered to be W3C-compliant, in that they conform to the set-forth standards and should deliver a consistent web experience across browsers.

JavaScript engines are typically developed by web browser vendors, and every major browser has one. The use of JavaScript engines is not limited to browsers. For example, the Chrome V8 engine is a core component of the popular Node.js and Deno runtime systems.

Non-browser environments

Host environments outside browsers come in different shapes and sizes, relies on popular JavaScript engines (V8, JavaScriptCore, etc.) to handle JavaScript language, provides addition platform-specific features as JavaScript frameworks, and not standardized by any specifications.

JavaScript in server-side has exploded in recent years with the help of Node.js and Deno runtime. They provide server-side computation including objects representing requests, clients, files, mechanisms to lock and share data.

  • Node.js - a server-side JavaScript environment based on Google’s V8 JavasScript engine, created by Ryan Dahl in 2009 and was heavily focused on event-driven HTTP servers. It brought server-side JavaScript to the mainstream, under development for over a decade, very stable and battle-tested.
  • Deno - a much younger alternative to Node, simple, modern, secure by default, uses V8, and built in Rust. No file, network, or environment access, unless explicitly enabled.

With introduction of mobile Javascript frameworks (React Native, NativeScript, Ionic, or Apache Cordova), you can now use JavaScript to develop truly universal apps that run in both iOS and Android. They allow you to develop UI elements using web technologies (HTML, CSS, React, Vue, Angular, etc.) and provide access to iOS and Android APIs via bridging.

  • React Native (RN) - the most popular solution to use JavaScript and React to develop mobile apps. In iOS, RN uses JavaScriptCore provided by platform. In Android, RN bundles the JavaScriptCore along with the application.
  • NativeScript - an open source framework for building truly native mobile apps with Angular, Vue.js, TypeScript, or JavaScript.
  • Ionic - an open source UI toolkit for building performant, high-quality mobile and desktop apps using web technologies — HTML, CSS, and JavaScript — with integrations for popular frameworks like Angular, React, and Vue.
  • Apache Cordova - an open-source mobile development framework. It allows you to use standard web technologies such as HTML5, CSS3, and JavaScript for cross-platform development, avoiding each mobile platforms’ native development language.

Typically, you create a desktop application for an operating system (OS) using each operating system’s specific native application frameworks. Electron makes it possible to write your application once using technologies that you already know: Chromium for displaying web content, Node.js for working with the local filesystem and the operating system, and Custom APIs for working with often-needed OS native functions.

  • Electron - a framework that enables you to create desktop applications with JavaScript, HTML, and CSS. These applications can then be packaged to run directly on macOS, Windows, or Linux, or distributed via the Mac App Store or the Microsoft Store.

Riding on the widespread popularity of JavaScript (particularly event-driven Node.js) in combination with low cost prototyping hardware, a new set of projects have emerged letting client side web developers use their skills to start controlling elements in the physical world.

  • Cylon.js - a JavaScript framework for robotics, physical computing, and the Internet of Things. It makes it incredibly easy to command robots and devices.
  • Tessel 2 - a robust IoT and robotics development platform. Leverage all the libraries of Node.JS to create useful devices in minutes.

Conclusion

It seems impossible to imagine software development without JavaScript these days. The merits of JavaScript aren’t limited to just web applications. If you possess JavaScript skills, you can easily migrate to any field including server side, mobile, or IoT development.

Related Posts

React-Admin - the best React framework to build dashboard

The best React framework to build admin dashboard which adapts to any backend

Node.js logging libraries

Notable libraries to write logs in Node.js applications

On the illusion of work-life balance

Getting things done in your professional life while still having time and energy to enjoy your personal life

Static Imports in JavaScript

Static declarations to import and export JavaScript modules