Last active
January 22, 2019 07:01
-
-
Save jaamaalxyz/41b9711ac027120d03d6b8ebc84ea8ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// var | |
var num = 7 | |
console.log(num) // 7 | |
// let | |
let age = 23 | |
console.log(age) // 23 | |
// const | |
const NAME = 'Jamal Uddin' | |
console.log(NAME) // Jamal Uddin | |
// arrow function | |
const foo = () => { | |
return bar | |
} | |
const ship = () => foo() | |
const multiply = (num1, num2) => num1 * num2 | |
// template string | |
const customer4 = (name, qty) => { | |
return `Customer name: ${name} | |
Product name: tomato | |
Per unit price: $15 | |
Total price: $${15 * qty} | |
Thanks for purchasing from us!` | |
} | |
console.log(customer4('Jamal', 100)) | |
// Customer name: Jamal | |
// Product name: tomato | |
// Per unit price: $15 | |
// Total price: $1500 | |
// Thanks for purchasing from us! | |
// spread operator | |
const animals = ['rat', 'cat', 'dog', 'goat'] | |
const fruits = ['apple', 'banana', 'mango'] | |
const mixed = [...animals, ...fruits] | |
console.log(mixed) // ["rat", "cat", "dog", "goat", "apple", "banana", "mango"] | |
// Maps | |
let course = new Map() | |
course.set('react', {description: 'ui'}) | |
course.set('jest', {description: 'testing'}) | |
console.log(course) // {"react" => {…}, "jest" => {…}} | |
// Sets | |
let books = new Set() | |
books.add = 'Dreams from my father' | |
books.add = 'Oliver stone' | |
books.add = 'War and Peace' | |
console.log(books.size) // 3 | |
// Building Promises | |
const spacePeople = () => { | |
return new Promise((resolve, reject) => { | |
const api = 'http://api.open-notify.org/astros.json' | |
const request = new XMLHttpRequest() | |
request.open('GET', api) | |
request.onload = () => { | |
if(request.status === 200) { | |
resolve(JSON.parse(request.response)) | |
} else { | |
reject(Error(request.statusText)) | |
} | |
} | |
request.onerror = (err) => reject(err) | |
request.send() | |
}) | |
} | |
spacePeople() | |
.then( | |
spaceData => console.log(spaceData), | |
err => console.error(new Error('cannot load space data')) | |
) | |
) | |
// async await with fetch | |
const githubUsersFollowers = async(userName) => { | |
try { | |
const response = await fetch(`https://api.github.com/users/${userName}/followers`) | |
const json = await response.json() | |
const followerList = json.map(user => user.login) | |
console.log(followerList) | |
} catch (err) { | |
console.log('data did not load', err) | |
} | |
} | |
githubUsersFollowers('jamal-pb95') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment