JS++ explained

JS++
Paradigm:Multi-paradigm

Imperative, structured, object-oriented, functional, generic

Family:ECMAScript
Designer:Roger Poon, Anton Rapetov
Developer:Onux
Latest Release Version:0.10.0
Typing:Gradual, static, dynamic
Scope:lexical
License:BSD
File Ext:.jspp, .js++, .jpp
File Formats:-->
Influenced By:C, C++, C#, Java, JavaScript

JS++ is a programming language for web development that extends JavaScript with a sound type system. It includes imperative, object-oriented, functional, and generic programming features. It is free and open-source software released under a BSD license.

History

JS++ first appeared on October 8, 2011.[1] [2] [3] The modern implementation was announced at DeveloperWeek 2016[4] and released on May 31, 2016.[5] [6] [7] [8] The language is designed by Roger Poon and Anton Rapetov.

Features

Sound gradual type system

Since JS++ is a superset of JavaScript, declaring data types for variables is optional. However, when types are declared, the types are enforced at both compile time and runtime.

Type annotations in JS++ use the traditional C/C++ syntax:

int x = 1;var y = 2;bool z = true;

Notably, this differs from TypeScript and ActionScript, which use a more verbose style:

var x: number = 1;var y: any = 2;var z: boolean = true;

The type system in JS++ is sound for ECMAScript and DOM API corner cases, including host objects, dynamic key-value pairs, Comet, JScript conditional compilation, dynamic return types, ActiveX, ECMAScript for XML, web browser garbage collector and cyclic reference counting bugs, conditional logic, and other edge and corner cases.[9] [10] This differs from other JavaScript supersets where types are optional and discarded at runtime via type erasure, such as in TypeScript.[11] [12]

Importing JavaScript libraries

JS++ can use JavaScript libraries using the one-line external statement as in the following example from the homepage of JS++:

import System;// Import JavaScript libraries in one line of codeexternal jQuery, $;

class Example

Object-oriented programming

While classes in JavaScript (ECMAScript 6) are syntactic sugar for prototypes under the hood,[13] JS++ classes resemble the classes found in classical programming languages such as C++, Java, and C# in terms of memory layout, performance, and semantics. "Classes" are a static concept, and they cannot be altered at runtime (during program execution) as is the case for JavaScript, Smalltalk, Lisp, and TypeScript, which rely on prototypes.[14] For example, private methods are private at both compile time and runtime, and external JavaScript objects cannot access private JS++ fields or methods—even if a reference to a JS++ object is obtained from JavaScript.

Example: object-oriented sorting

The following source code illustrates object-oriented sorting in JS++ using the IComparable interface and Comparison enumeration for type-safe and readable comparisons.[15] The custom sorting logic is one line of code in the overridden compare method below:

import System; class Employee : IComparable

Employee zig = new Employee("Zig", "Ziglar");Employee john = new Employee("John", "Smith");Employee abe = new Employee("Abe", "Lincoln");

Employee[] employees = [zig, john, abe ];employees.sort;Console.log(employees.join(", "));

// Output:// Abe Lincoln, John Smith, Zig Ziglar

Thus, in the code above, the custom sorting logic provided is:

return this.lastName.compare(that.lastName);

Likewise, to call the sort:

employees.sort;

For printing the sorted results:

Console.log(employees.join(", "));

Example: encapsulation by default

JS++ provides encapsulation by default. In the following example, the fields x and y are private by default, even if no access modifier is specified. The methods getX and getY are public by default. This enables a more concise class definition syntax, as illustrated in the Point class below:[16]

class Point

Out-of-bounds analysis

An out-of-bounds access usually occurs with arrays and other containers. For example, when we access the 100th element of a 3-element array, we have an out-of-bounds access:

int[] arr = [1, 2, 3 ];Console.log(arr[100]); // out-of-bounds access, 'arr' does not have an element at index 100

In Java and C#, this can result in an exception and program termination. In C, this can result in buffer overflows or segmentation faults. C++ has varying semantics, such as default initialization, exceptions, segmentation faults, or buffer overflows.[17] [18]

JS++ can efficiently analyze and prevent out-of-bounds errors at compile time.[19] [20] [21]

JavaScript has the notion of null and undefined values, where null means a value is present but it's an empty value, and undefined means there isn't a value there at all. JS++ extends this intuition further to differentiate between empty values and out-of-bounds accesses.

Consider the following code, with a nullable int type represented with int?:

int[] a = [1, 2 ];int? value1 = a[2];if (value1

null) int?[] b = [1, null ];int? value2 = b[2];if (value2

null)

While nullable types can represent an out-of-bounds access, it falls apart when the array might contain nullable values as illustrated above. Instead, JS++ introduces an additional concept in addition to null values: undefined values. Recall that JS++ extends the JavaScript notion that null means a value is present but is an empty value, while an undefined value means a value does not exist at all. JS++ uses the concept of "a value does not exist at all" to mean an out-of-bounds access has occurred, and this concept is known in JS++ as "existent types."

Therefore, the previous example can be amended. The existent type int+ means "int or out of bounds" and int?+ means "int, null, or out of bounds":

int[] a = [1, 2 ];int? value1 = a[2];if (value1

undefined)

int?[] b = [1, null ];int?+ value2 = b[2];if (value2

undefined)

Intuitively, this means existent types cannot be used as the underlying type for array elements. JS++ enforces this at compile time:

int+[] arr = []; // ERROR

style="color: silver; background: black;">[ ERROR ] JSPPE5204: Existent type `int+' cannot be used as the element type for arrays

Instead of following every conditional branch or virtual method call path, which would result in path explosion and exponential compile times, existent types have essentially the same compile-time analysis cost as int, bool, and other primitive types. Consequently, compile times have been shown to be unaffected (±1-2ms) by the introduction of existent types. Since existent types are used for all array and container types in JS++ (such as hash maps, Stack<T>, and Queue<T>), JS++ containers are thus guaranteed to not have out-of-bounds errors.

In JS++, undefined is a value that cannot be changed. In JavaScript (ECMAScript 3), undefined is a mutable property of the global object, resulting in circumstances where "undefined" can be "defined."[22] Thus, existent types would not have been possible in pure JavaScript, as arrays can contain elements with the undefined value, undefined can be defined, or other edge and corner cases that are prevented in JS++.[23]

Also, in comparison to Java and early object-oriented languages such as Eiffel,[24] [25] JS++ does not default initialize objects to null. Instead, the compiler enforces initialization by the programmer:

class Car

Car car;

style="color: silver; background: black;">[  ERROR  ] JSPPE6000: Variable `car' is not initialized at line 3 char 4

Therefore, since existent types are deeply embedded into the language, JS++ can guarantee that out-of-bounds errors never occur.[26]

Databases

The concept of existent types can be extended outside of containers. For example, in MySQL, columns can be nullable.[27] [28] If the row does not exist for a specified condition (e.g. WHERE clause), the undefined value can be returned. However, if the row does exist but the value at the column is empty, a null value can be returned instead. This can simplify the code and interfaces to the data access layer.

Integer types

JS++ provides 8-bit, 16-bit, 32-bit, and 64-bit integer types as well as floating point types:

byte b1 = 0xFF; // unsigned 8-bitsigned byte b2 = -1; // signed 8-bitshort s1 = 1; // signed 16-bitunsigned short s2 = 1; // unsigned 16-bitint x1 = 0; // signed 32-bitunsigned int x2 = 0; // unsigned 32-bitlong z1 = 1; // signed 64-bitunsigned long z2 = 1; // unsigned 64-bit

float f = 0.5; // single-precision floating pointdouble d = 0.5; // double-precision floating point

From the project homepage:

// You're not required to declare the type for a variable and you can just// keep writing regular JavaScript (again, NO learning curve):var offset = 0;

// But, if you do, this next variable will always remain an 'unsigned int' - even at runtime.// You'll never see NaN ("Not a Number") runtime errors again.// This variable is 'unsigned' so it's also guaranteed to never be negative.unsigned int pageHeight = $(document).height;

Block scoping

All variables in JS++ are block-scoped, including the JavaScript var statement.[29] [30] [31] Thus, there is no need for two different variable declaration keywords with different scoping rules, such as var and let co-existing simultaneously in JavaScript (ECMAScript 6).

Development tools

Compiler

The JS++ compiler is available for Windows, macOS, and Linux. It is a source-to-source compiler which emits JavaScript source code as an intermediate representation.

The compiler is developed with C/C++, and the developers claim there are "fewer than 10 open bug reports in the core compiler" after 3.5 years of engineering and 400,000 lines of code.[32]

Editor integration

JS++ integrates with various code editors including Visual Studio Code, Atom, and Sublime Text.[33] [34] [35]

Build tools

JS++ can be integrated with third-party build tools like Webpack.[36]

Release history

Version numberRelease dateChanges
0.01Alpha version, initial release
0.011Alpha version
0.012Alpha version
0.013Alpha version
0.014.1Alpha version
0.4.1Beta version, array and callback types, character literals, integral suffixes, removed ECMAScript ASI
0.4.2Modules, function overloading, dead code elimination, editor integrations
0.4.2.1Bug fixes
0.4.2.2Source map debugging
0.4.2.4Support for Mac OS X, C-style casts, callback and array conversions
0.5.0Classes
0.5.1'foreach' loops
0.5.2BSD License, Interfaces, Abstract Classes, Virtual Methods, Auto-boxing
0.7.0All ECMAScript 3 features via Array and Standard Library
0.8.0Generic programming, Dictionary, multi-line strings, .js++ file extension
0.8.1auto, catch-all clauses, standard library modules for handling time, bug fixes
0.8.4New string functions, advanced generics, bug fixes, standard library expansion
0.8.5Bug fixes
0.8.10Faster compile times, stacks, queues, Unicode, Base64, generic default constraint rules
0.9.0Efficient compile time out-of-bounds error analysis
0.9.1Bug fixes
0.9.2Final (immutable) variables and default to 64-bit for macOS Catalina

See also

Notes and References

  1. Web site: JavaScript++: New, Powerful Language for Better Web Development . https://web.archive.org/web/20111017221312/http://jspp.javascript.am/ . dead . 17 October 2011 . 17 October 2011.
  2. News: 12 October 2011 . C++ et Javascript = Javascript++ . La ferme du web . dead . https://web.archive.org/web/20111012143226/http://www.lafermeduweb.net/veille/c-et-javascript-javascript-123284133702156289.html . 12 October 2011.
  3. News: 18 October 2011 . Index of /downloads . https://web.archive.org/web/20111018172906/http://jspp.javascript.am/downloads/ . dead . 18 October 2011.
  4. News: 13 February 2016 . JavaScript Conference - DeveloperWeek 2016 - February 12–18 . https://web.archive.org/web/20160213204925/http://www.developerweek.com/javascript-conference/ . dead . 13 February 2016.
  5. News: Poon . Roger . May 31, 2016 . JS++ Goes Into Public Beta . Onux.com.
  6. News: Handy . Alex . June 1, 2016 . Onux seeks to fix JavaScript's lack of type safety . SD Times.
  7. News: Krill . Paul . June 6, 2016 . New compiler tackles JavaScript's weak typing . InfoWorld.
  8. News: Cimpanu . Catalin . June 9, 2016 . jQuery 3.0 Released and Other JavaScript News . Softpedia.
  9. Web site: The JS++ Type System, Appendix B: Problems (Why was this hard to solve?). 10 February 2020.
  10. 10296313. Roger Poon. Safely consuming dynamically-typed code from a statically-typed programming language. US. 2019-05-21. 2018-11-18. patent.
  11. News: Bridgwater. Adrian . June 13, 2016 . Onux JS++, an answer to JavaScript 'brittle' type safety?. Computer Weekly. https://web.archive.org/web/20160722151154/http://www.computerweekly.com/blog/Open-Source-Insider/Onux-JS-an-answer-to-JavaScript-brittle-type-safety. 2016-07-22.
  12. Web site: The JS++ Type System . Onux.com.
  13. Web site: Classes. 2025-06-20. MDN Web Docs.
  14. Book: Meyer, Bertrand. Object-Oriented Software Construction. 1988. 94,100.
  15. Web site: Tips & Tricks: Object-oriented Sorting in JS++ with IComparable. May 28, 2019. June 20, 2025. Poon. Roger.
  16. Web site: Tips & Tricks: Only Fields are 'private' by Default. Poon. Roger. June 10, 2018. June 20, 2025.
  17. Web site: std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::operator[] - cppreference.com]. June 20, 2025. en.cppreference.com.
  18. Web site: std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::at - cppreference.com. June 20, 2025. en.cppreference.com.
  19. News: Díaz . Fabio . January 23, 2019 . JS++, the JavaScript superset, is getting rid of out-of-bounds errors . Akuaroworld . February 1, 2019 . February 1, 2019 . https://web.archive.org/web/20190201121700/https://www.akuaroworld.com/js-the-javascript-superset-is-getting-rid-of-out-of-bounds-errors/ . dead .
  20. News: Cardoza . Christina . January 16, 2019 . JS++ programming language looks to solve out-of-bounds errors . SD Times.
  21. News: Poon . Roger . January 11, 2019 . JS++ 0.9.0: Efficient Compile Time Analysis of Out-of-Bounds Errors . Onux.com.
  22. ECMAScript Language Specification. Ecma International. March 24, 2000. 15.1.1.3. 86.
  23. Web site: Compatibility with JavaScript - JS++ & JavaScript Documentation. June 20, 2025.
  24. Book: Meyer, Bertrand. Object-Oriented Software Construction. 1988. 70–77.
  25. Web site: Void-safety: Background, definition, and tools. June 24, 2025. Eiffel.
  26. 11023214. Roger Poon. Anton Rapetov. Preventing runtime out-of-bounds errors and exceptions with nominal types. US. 2021-06-01. 2019-07-27. patent.
  27. Web site: MySQL :: MySQL 8.4 Reference Manual :: 13.6 Data Type Default Values. June 20, 2025. MySQL.
  28. Web site: MySQL :: MySQL 8.4 Reference Manual :: 5.3.4.6 Working with NULL Values. June 20, 2025. MySQL.
  29. Web site: Scoping - JS++ & JavaScript Documentation. June 24, 2025.
  30. Web site: Compatibility with JavaScript - JS++ & JavaScript Documentation. June 24, 2025.
  31. Web site: JS++ 0.9.1: Bug Fixes . July 2019 .
  32. Web site: Compiler Software Engineering Methods. Poon. Roger. October 9, 2019. June 24, 2025.
  33. News: JavaScript superset JS++ adds dead code elimination and more . . October 19, 2016.
  34. News: Cardoza . Christina . October 19, 2016 . JS++ 0.4.2 released with code editor integrations, modules and dead code elimination . SD Times.
  35. News: Clark . Geneva . October 20, 2016 . JS++ 0.4.2 Release - Upgraded With Modular Design, Dead Code Elimination, and Multiple Code Editors . Zeomag.
  36. Web site: Phoenix . Ingwie . 7 December 2018 . Proof of Concept: Using JS++ with WebPack . Ingwie Phoenix . GitHub.