Dealing with Gaps

Transpiler

Convert newer language syntax like

if (something) {
    let x = 3;
    console.log(x);
}
else {
    let x = 4;
    console.log(x);
}

to syntax that is compatible with older versions of the language (since JS is not forward compatible), like

var x$0, x$1;
if (something) {
    x$0 = 3;
    console.log(x$0);
}
else {
    x$1 = 4;
    console.log(x$1);
}

Popular choice for JS transpiler: babeljs.io.

(Example from You Don't Know JS Yet (book series) - 2nd Edition, Kyle Simpson, github.com.)

Polyfill ("shim")

Pitfalls

negative indexing

Doesn't exist! To properly index the last element

var arr = [1,2,3];
arr[arr.length - 1] = 5;

comparison

NaN === NaN;            // false
0 === -0;               // true
[ 1, 2, 3 ] === [ 1, 2, 3 ];    // false
{ a: 42 } === { a: 42 }         // false
(x => x * 2) === (x => x * 2)   // false
var x = [ 1, 2, 3 ];

// assignment is by reference-copy, so
// y references the *same* array as x,
// not another copy of it.
var y = x;

y === x;              // true
y === [ 1, 2, 3 ];    // false
x === [ 1, 2, 3 ];    // false

I

< and > perform coercion

var x = "10";
var y = 9;

x < y;      // false

but when they are of the same type, they use alphabetic

var x = "10";
var y = "9";

x < y;      // true, watch out!

Test

(test)

x = b
print("hello world")