# ๐ ES6 EcmaScript 6
- List of features in es6 or ECMAScript 2015 (opens new window)
- We can easily redeclare a variable. Its a big no no
var counter = 10
// ... some code
var counter = 5
- Variables declared outside function could be used inside functions.
- However functions declared inside fucntion could not be used outside
# String Concatination
// older syntax
console.log('value = ' + value);
// newer syntax - template delimeters
console.log(`value = ${value}`);
# Object Deconstruction
# Arrow Function
that = this non-sense
- Arrow function preserves the references
- If you use normal
function() {..}
, references tothis
are not preserved - Declare default parametrs with in the arrow function
const user ={
name: 'Ed',
age: 25,
sayName: function() {
console.log(`My name is ${this.name}`);
const fullName = () => {
console.log(`name is ${this.name} and age is ${this.age}`);
};
fullName();
}
}
// practical scenario
button.addEventListner('click', fucntion() {
this // means button
})
Iterating over List/ Arrays
someList.foreach((item, index) => {
console.log(`Item = ${item} at index ${index}`);
})
- Use
map()
to transform each element in array inplace
# Array Filters
- get only a particular item from list
# Constructor and Classes
- generally starts with caps letter
new
creates a copy- How to add properties and methods to classes?
ClassName.Prototype.methoName = function() { ... }
call()
- class inheritance
extends
# Callbacks vs Promises
- Variables
- String Concatenation
- Object Literals
- Object Deconstruction
- Arrow Functions
- Default Parameters
- Array Functions
- Constructor Functions and Classes
- Promise
.then
.catch
# ๐ References
โ devtools ES6 Features โ