The mJS Language

What the embedded mJS interpreter supports — a strict subset of ES6 designed for microcontrollers.

Scripts run on mJS, a JavaScript engine designed for microcontrollers with limited resources. Its main design goals are a small footprint and simple C/C++ interoperability — on 32-bit ARM the engine takes about 50 kB of flash and less than 1 kB of RAM. mJS implements a strict subset of ES6:

  • Any valid mJS code is valid ES6 code.
  • Any valid ES6 code is not necessarily valid mJS code.

Restrictions

  • No standard library. No String, Number, RegExp, Date, Function, etc. — but the byte-level string, number and array methods documented in this category are built in, and JSON.parse() / JSON.stringify() are available.
  • No closures, only lexical scoping (nested functions are allowed).
  • No exceptions.
  • No new. To create an object with a custom prototype use Object.create(), which is available.
  • Strict mode only.
  • No var, only let.
  • No for..of, arrow functions (=>), destructuring, generators, proxies or promises.
  • No getters, setters, valueOf, prototypes, classes or template strings.
  • No == or != — only === and !==.

Byte strings

mJS strings are byte strings, not Unicode strings: 'ы'.length === 2, 'ы'[0] === '\xd1', 'ы'[1] === '\x8b'. This means an mJS string can represent any binary data chunk — which is exactly how the bin buffer functions use them.