Interview Questions – ES6 Questions


  1. What is traceur?
    • ES6 -> ES5
    • Traceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to use features from the future today. Traceur supports ES6 as well as some experimental ES.next features.Traceur’s goal is to inform the design of new JavaScript features which are only valuable if they allow you to write better code. Traceur allows you to try out new and proposed language features today, helping you say what you mean in your code while informing the standards process.JavaScript’s evolution needs your input. Try out the new language features. Tell us how they work for you and what’s still causing you to use more boilerplate and “design patterns” than you prefer

     

  2. What are the required node_modules to makes traceur working properly
    • $ npm install traceur
      $ npm install traceur-runtime
  3. Why do you need traceur-runtime?
  4. What is the node command to compile ES6 to ES5?
Advertisements

Self Invoking Function (Tutorial – JS)


Self invoking functions are used to stop global scope pollution and ensure the code doesn’t conflict with other code in the page.


(function (a, b) { //Temporary name space for all
// the variables within the function

//code goes here

}() //Invoke the function

); //Without this enclosing parenthesis JS
//will identify this as a function declartion statement only

 

Working example – JSFiddle

var p = 8;
var q = 7;

(function (a, b) {
var x = a * a ;
var y = b * b;
var z = Math.sqrt(x + y);
var r = p + q; // Effects of global scope pollution
console.log(r);
console.log(z);

}(3, 4));

console.log(p); // declaration of variables outside polluted the global scope
console.log(z); // “ReferenceError: z is not defined” = Global scope is not polluted