Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.
JavaScript always initializes, and then declares variables.
function hoist() {
a = 20;
var b = 100;
}
| function *getUser(username) { | |
| const uri = 'https://api.github.com/users/' + username | |
| const response = yield fetch(uri) | |
| const parsedResponse = yield response.json() | |
| console.log(parsedResponse) | |
| } | |
| getUser('maecapozzi') |
| const makeHTTPRequest = (username) => { | |
| const url = 'https://api.github.com/users/' + username | |
| fetch(url) | |
| .then(response => response.json()) | |
| .then(response => console.log(response)) | |
| } | |
| makeHTTPRequest('maecapozzi') |
| const makeHTTPRequest = (url, methodType, callback) => { | |
| const xhr = new XMLHttpRequest() | |
| xhr.open(methodType, url, true) | |
| xhr.onreadystatechange = () => { | |
| if (xhr.readyState === 4 && xhr.status === 200) { | |
| callback(xhr.responseText) | |
| } | |
| } | |
| xhr.send() | |
| } |
| const greetUser = () => { | |
| new Promise((resolve, reject) => { | |
| let name = prompt('Please enter your name') | |
| resolve(name) | |
| }).then((name) => { | |
| console.log('Hello ' + name) | |
| }) | |
| } |
| const greeting = (name) => { | |
| console.log('Hello ' + name) | |
| } | |
| const processUserInput = (callback) => { | |
| let name = prompt('please enter your name') | |
| callback(name) | |
| } | |
| processUserInput(greeting) |
| class Stack { | |
| constructor () { | |
| this.state = { | |
| storage: '', | |
| count: 0, | |
| mostRecent: '' | |
| } | |
| }; |
| import React from 'react' | |
| import axios from 'axios' | |
| import UserProfile from './UserProfile' | |
| class UserProfileContainer extends React.Component { | |
| state = {} | |
| componentDidMount() { | |
| axios.get('http://localhost:3001/users', { | |
| params: { |