JavaScript ES6 Cheat sheet

JavaScript ES6 Cheat sheet
Techiio-author
Written by Debarghya DasJanuary 20, 2022
6 min read
JavaScript
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Debarghya Das

Junior Front-End Developer

Let's discuss, what are the JavaScript ES6 cheat sheets.

About JavaScript ES6

JavaScript ES6 (also known as ECMAScript 2015 or ECMAScript 6) is the newer version of JavaScript that was introduced in 2015. ECMAScript is the standard that the JavaScript programming language uses. ECMAScript provides the specification on how JavaScript programming language should work.

blogpost

JavaScript ES6 cheat sheets are:

Arrow function:

const sum = (a, b) => a + b 
console.log(sum(2, 6)) // prints 8

Object property assignment:

const a = 2
const b = 5
const obj = { a, b } 
// Before es6: 
// obj = { a: a, b: b } 
console.log(obj) 
// prints { a: 2, b: 5 }

Object function assignment:

const obj = {
a: 5,
b() { 
console.log('b')
  }
}

Default parameters:

function print(a = 5) {
 console.log(a)
}
print() // prints 5
print(22) //prints 22 

Let scope:

let a = 3
if (true) {
  let a = 5
console.log(a) // prints 5
}
console.log(a) // prints 3

Object.assing():

const obj1 = { a: 1 }
const obj2 = { b: 2 }
const obj = object.assing( {} ,
       obj1, obj2)
console.log(obj3)
// { a: 1, b: 2 }

Object.entries():

const obj = {
 firstname: 'firstname' ,
 lastname: 'lastname' ,
 age: 24,
 country: 'India',
};
const entries = object.entries(obj);
/* returns an array of [key, value]
 pairs of the object passed */
console.log(entries);
/* prints
[
['firstname', 'FirstName'],
['lastname', 'LastName'],
['age', 24],
['country', 'India'] 
]; */

Const:

// can be assigned only once
const a = 55
a = 44 // throws an error

Promises with family:

promise
 .then((result) => { . . .})
 .catch((error) => {. . .})
 .finally(() => { /* logic
independent of success/error */ })
/* The handler is called when the 
promise is fulfilled or rejected.*/

Multiline string:

console.log(`
 This is a
 multiline string
`)

Template strings:

const name = 'world'
const message = `Hello ${name}`
console.log(message)
// prints "Hello World"

Spread operator:

const a = {
  firstname: "FirstName",
  lastname: "LastName",
}
const b = {
 . . . a,
lastname: "LastName2",
canSing: true,
}
console.log(a)
//{firstname: "FirstName , lastname: "LastName1"}
console.log(b)
/* {firstname: "FirstName , lastname: "LastName2",
canSing = true} */
*/ great for modifying objects without side
effects/affecting the original */

Exponent operator:

const byte = 2 ** 8
// same as: Math.pow(2, 8)

Spread operator:

const a = [ 1, 2 ]
const b = [ 3, 4]
const c = [ . . . a, . . . b ]
console.log(c) // [1, 2, 3, 4]

String includes():

console.log('apple' .includes('pl'))
// prints true
console.log('apple' .includes('tt'))
// prints false

String startsWith():

console.log('apple'.startsWith('ap'))
//prints true
console.log('apple'.startsWith('bb'))
//prints false

String repeat():

console.log('ab'.repeat (3))
//prints "ababab"

Destructuring array:

let [a, b] = [3, 7];
console.log(a); // 3
console.log(b); // 7

Destructuring object:

let obj = {
a: 55,
b: 44
};
let { a, b } = obj;
console.log(a); // 55
console.log(b); // 44

Destructuring nested objects:

const Person = {
name: "Harry Potter",
age: 29,
sex: "male",
materialStatus: "single",
address : {
country: "USA"
state: "Nevada",
city: "Carson City",
pinCode: "500014",
},
};
const { address : { state, pincode }, name } - Person;
console.log(name, state, pinCode)
// Harry Potter Nevada 500014
console.log(city) // ReferenceError

JavaScript
EcmaScript
JavaScript ES6
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance