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;
}
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: { |
class Stack { | |
constructor () { | |
this.state = { | |
storage: '', | |
count: 0, | |
mostRecent: '' | |
} | |
}; |
const greeting = (name) => { | |
console.log('Hello ' + name) | |
} | |
const processUserInput = (callback) => { | |
let name = prompt('please enter your name') | |
callback(name) | |
} | |
processUserInput(greeting) |
const greetUser = () => { | |
new Promise((resolve, reject) => { | |
let name = prompt('Please enter your name') | |
resolve(name) | |
}).then((name) => { | |
console.log('Hello ' + name) | |
}) | |
} |
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 makeHTTPRequest = (username) => { | |
const url = 'https://api.github.com/users/' + username | |
fetch(url) | |
.then(response => response.json()) | |
.then(response => console.log(response)) | |
} | |
makeHTTPRequest('maecapozzi') |
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 getUser = async (username) => { | |
const uri = 'https://api.github.com/users/' + username | |
const response = await fetch(uri) | |
const parsedResponse = await response.json() | |
console.log(parsedResponse) | |
} | |
getUser('maecapozzi') |
import React, { Component } from 'react' | |
import './App.css' | |
import axios from 'axios' | |
class App extends Component { | |
constructor () { | |
super() | |
this.state = { | |
username: '' |