A. Necessities #

Created Thursday 25 March 2021

These were necessary features common in other programming languages:

  1. let and const - solve hositing and scope problems.
  2. arrow functions - solve context binding
  3. Template literals - easy string builder, ability to add DSL.

1. let and const #

2. Arrow functions #

const f = num => num\*2; // single argument, single expression
f() // call

// Multiline body - no return
const f = () =>
{
console.log('Hello');
console.log('World'); // returns undefined
}

//Multiline - with return
const f = (a, b) => {
a\*2 = b;
return a+b;
}; //

(()=>console.log(2))(); // Arrow function as IIFE

Note:

3. Template Literals #

  1. For carrying JS code. ${ console.log(2); } // prints 2 on string evaluation

    ${ (() => { console.log('Autodestruct sequence intiated'); })() } // pretty hacky and dangerous

  2. DSL injection(Domain Specific Language)

    p.innerHTML(<h1> DSL injected </h1>);