-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Exponent operator and Promises with finally pr #24
- Loading branch information
Leon Gilyadov
authored and
Leon Gilyadov
committed
Aug 22, 2020
1 parent
101413d
commit e95722e
Showing
3 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,335 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>ES6 cheat sheet</title> | ||
<meta type="keywords" content="ES6 Cheatsheet,es6" /> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="styles/prism-atom-dark.css" /> | ||
<link rel="stylesheet" href="styles/atom-one-dark.css" /> | ||
<link rel="stylesheet" href="styles/styles.css" /> | ||
<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" /> | ||
<style> | ||
h1, | ||
h3 { | ||
color: #998e11; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<header data-aos="zoom-in-up"> | ||
<h1><img src="./images/es6_logo.svg" />ES6 cheat sheet</h1> | ||
<button onclick="openPDF()"><img src="./images/pdf.svg" />PDF</button> | ||
</header> | ||
<article> | ||
<section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Arrow function | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const sum = (a, b) => a + b | ||
|
||
console.log(sum(2, 6)) // prints 8 | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Default parameters | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">function print(a = 5) { | ||
console.log(a) | ||
} | ||
|
||
print() // prints 5 | ||
print(22) // prints 22 | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
let scope | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">let a = 3 | ||
|
||
if (true) { | ||
let a = 5 | ||
console.log(a) // prints 5 | ||
} | ||
|
||
console.log(a) // prints 3 | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
const | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">// can be assigned only once: | ||
const a = 55 | ||
|
||
a = 44 // throws an error | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Multiline string | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">console.log(` | ||
This is a | ||
multiline string | ||
`)</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Template strings | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const name = 'Leon' | ||
const message = `Hello ${name}` | ||
|
||
console.log(message) // prints "Hello Leon" | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
String includes() | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">console.log('apple'.includes('pl')) // prints true | ||
console.log('apple'.includes('tt')) // prints false</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
String startsWith() | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">console.log('apple'.startsWith('ap')) // prints true | ||
console.log('apple'.startsWith('bb')) // prints false</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
String repeat() | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">console.log('ab'.repeat(3)) // prints "ababab" | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Destructuring array | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">let [a, b] = [3, 7]; | ||
|
||
console.log(a); // 3 | ||
console.log(b); // 7</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Destructuring object | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">let obj = { | ||
a: 55, | ||
b: 44 | ||
}; | ||
|
||
let { a, b } = obj; | ||
|
||
console.log(a); // 55 | ||
console.log(b); // 44 | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
object property assignement | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">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 } | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
object function assignement | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const obj = { | ||
a: 5, | ||
b() { | ||
console.log('b') | ||
} | ||
} | ||
|
||
obj.b() // prints "b" | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
spread operator | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const a = [ 1, 2 ] | ||
const b = [ 3, 4 ] | ||
|
||
const c = [ ...a, ...b ] | ||
|
||
console.log(c) // [1, 2, 3, 4] | ||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Object.assign() | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const obj1 = { a: 1 } | ||
const obj2 = { b: 2 } | ||
|
||
const obj3 = Object.assign({}, obj1, obj2) | ||
|
||
console.log(obj3) // { a: 1, b: 2 } | ||
|
||
</code></pre> | ||
|
||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Object.entries() | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const obj = { | ||
firstName: 'Vipul', | ||
lastName: 'Rawat', | ||
age: 22, | ||
country: 'India', | ||
}; | ||
|
||
const entries = Object.entries(obj); | ||
/* returns an array of [key, value] | ||
pairs of the object passed | ||
*/ | ||
|
||
console.log(entries); | ||
/* prints | ||
[ | ||
['firstName', 'Vipul'], | ||
['lastName', 'Rawat'], | ||
['age', 22], | ||
['country', 'India'] | ||
]; | ||
*/ | ||
</code></pre> | ||
|
||
<span style="font-size: 14px;float: right;position: unset;color: #9599a0;"> | ||
Author: Vipul Rawat | ||
</span> | ||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
spread operator | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const a = { | ||
firstName: "Barry", | ||
lastName: "Manilow", | ||
} | ||
|
||
const b = { | ||
...a, | ||
lastName: "White", | ||
canSing: true, | ||
} | ||
|
||
console.log(a) // {firstName: "Barry", lastName: "Manilow"} | ||
|
||
console.log(b) // {firstName: "Barry", lastName: "White", canSing: true} | ||
|
||
// great for modifying objects without side effects/affecting the original | ||
</code></pre> | ||
|
||
<span style="font-size: 14px;float: right;position: unset;color: #9599a0;"> | ||
Author: Layton Gilbraith | ||
</span> | ||
</div> | ||
</section><section data-aos="zoom-in-up"> | ||
<h3 | ||
> | ||
Destructuring Nested Objects | ||
</h3> | ||
<div class="snippet"> | ||
<pre><code class="language-javascript">const Person = { | ||
name: "John Snow", | ||
age: 29, | ||
sex: "male", | ||
materialStatus: "single", | ||
address: { | ||
country: "Westeros", | ||
state: "The Crownlands", | ||
city: "Kings Landing", | ||
pinCode: "500014", | ||
}, | ||
}; | ||
|
||
const { address : { state, pinCode }, name } = Person; | ||
|
||
console.log(name, state, pinCode) // John Snow The Crownlands 500014 | ||
console.log(city) // ReferenceError</code></pre> | ||
|
||
<span style="font-size: 14px;float: right;position: unset;color: #9599a0;"> | ||
Author: Vishal Lakkapathri | ||
</span> | ||
</div> | ||
</section> | ||
</article> | ||
<footer>Copyright © Leon Gilyadov 2018 - 2020</footer> | ||
</div> | ||
|
||
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-121688555-2"></script> | ||
<script src="scripts/prism.js"></script> | ||
<script src="https://unpkg.com/aos@next/dist/aos.js"></script> | ||
<script src="scripts/scripts.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const byte = 2 ** 8 | ||
|
||
// Same as: Math.pow(2, 8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
promise | ||
.then((result) => { ··· }) | ||
.catch((error) => { ··· }) | ||
.finally(() => { // logic independent of success/error }) | ||
|
||
// The handler is called when the promise is fulfilled or rejected. |