Troy  Marvin

Troy Marvin

1593008048

ES6 Slides

Slides presenting major ES6 features and probable ES7 features. Also highlights what features are supported in node 4.2.*, the current LTS release

#es6 #node.js #es6 slides #programming

What is GEEK

Buddha Community

ES6 Slides
Troy  Marvin

Troy Marvin

1593008048

ES6 Slides

Slides presenting major ES6 features and probable ES7 features. Also highlights what features are supported in node 4.2.*, the current LTS release

#es6 #node.js #es6 slides #programming

ES6 Reduce Helper and ES6-Equivalent Code Using Reduce

Consider a simple scenario where you have an array of numbers and you want to return the sum of all elements in that array.

We will see that it’s a solution in ES5 and that it’s equivalent in ES6 to using reduce helper.

ES5 Code

  1. var numbers=[10,70,50,20];   
  2. var sum=0;  
  3. function additionOfElementsInArray(){  
  4.    for(var i=0;i<numbers.length;i++){  
  5.          sum += numbers[i]  
  6.    }  
  7.    return(sum);  
  8. }  
  9.    
  10. additionOfElementsInArray();  

The above code will return an output of 150.

ES6-Equivalent Code Using Reduce

  1. const numbers=[10,70,50,20];   
  2.    
  3. numbers.reduce(function(sum,numberElement){  
  4.    
  5.    return sum += numberElement;  
  6.    
  7. } ,0 );  

The above code will also return output as 150.

You can write the same code in ES6 using Reduce Helper with arrow function as follows, which will return the same output.

  1. const numbers=[10,70,50,20];  
  2.    
  3. numbers.reduce((sum,numberElement)=>sum += numberElement,0);

#es6 #es5 code #es6-equivalent code

Myriam  Rogahn

Myriam Rogahn

1594649520

ES6 Concepts - Part One

Constants

Constants are block-scoped variables/arrays/objects which cannot be reassigned or redeclared in the same scope (Scope is defined by the nearest curly braces). Const declaration creates a read-only reference to a value but it is not immutable.

Syntax - const nameN = valueN;

Variable scope

Constant scope can be global/local depending on the block in which it is declared. However, you cannot access constant as window object property.

e.g.

constPI = 3.14;

console.log(window.PI) //output: undefined

Cons

Slow performance if code executes in temporal dead zone (i.e. accessing block scoped variable before definition is evaluated. Block scoped variables are not hoisted therefore accessing it before definition evaluation results in ReferenceError.)

#constants #es6 #es6 concepts

Jarrod Howe

Jarrod Howe

1607326380

ES6 Tutorial For Beginners - What Is ES6?

This is a short introductory video to explain the whys and hows behind the ECMAScript language specification, widely known as ES6.

#es6 #javascript #web-development

Madelyn  Frami

Madelyn Frami

1603742940

ES6 JavaScript— “this” keyword

Try to summarize the usage of “this” with examples

  • Every function created with the function keyword or with the method shorthand has its own “this”, and it generally binds to “who” called it.
  • Arrow functions don’t bind “this” to anything, the “this” inside depends on the surrounding context

Example 1

“handler” declared by error function here, that means the “this” is nothing, just same as outside the handler, thus the output is Window object

const handler = () => {
 console.log(this);
};
btn1.addEventListener('click', handler);

Output

Window {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}

#es6-in-depth #self-learning #javascript-tips #es6-js #self-taught #javascript