NOTE: You are viewing documentation for the MoovJS/Adapt version of the Moovweb SDK
View documentation for next-gen Moovweb XDN & PWA framework
Moovweb | ES6 Overview
Menu Developer Moovweb University

ES6 Overview

The Moovweb SDK is built on Node 6, which includes ECMAScript 2015 (ES6) features and syntax.

The full ECMAScript 2015 spec can be found here.

Some of the more useful features for building Moovweb projects are as follows.

let/const Keywords

let can be used to define block-scoped variables. This can be used in place of var in nearly every case in your projects.

const can be used for single-assignment variables.

Template Strings

Template strings, signified by backticks (`), allows for variable interpolation in strings, as well as multiline strings.

let testString1 = `Line breaks here
will actually work.`

let favoriteNumber = "520";
let testString2 = `My favorite number is ${favoriteNumber}.`; // > "My favorite number is 520."

Arrow Functions

Arrow functions provide for a syntactic function shorthand, using =>.

let testFunction = (x) => x + 1;
testFunction(5); // 6

Arrows share the lexical this as their surrounding code.

let bill = {
  name: "bill",
  getName: function() {
    var self = this;
    return (function() {
      return; // if we use `this`, it will return undefined

let bill2 = {
  name: "bill",
  getName: function() {
    return (() =>; // `this` knows to refer to the outer function's `this`

bill.getName(); // 'bill'
bill2.getName(); // 'bill'

Destructuring Assignment

Destructuring allows you to assign distinct variables by extracting data from arrays or objects with a specific pattern.

let [a, , b] = [1, 2, 3];
console.log(a); // 1
console.log(b); // 3

let {c, d} = {c: 1, d: 2, e: 3};
console.log(c); // 1
console.log(d); // 2