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
const express = require('express') | |
const path = require('path') | |
const app = express() | |
const port = process.env.PORT || 8000 | |
app.use(express.static(path.join(__dirname, '/public'))) | |
app.get('*', function (req, res) { | |
res.sendFile(path.resolve(__dirname, 'public', 'index.html')) | |
}) |
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
const axios = require('axios') | |
const getGeoAddress = encodedAddress => | |
axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`) | |
.then(response => { | |
return { | |
lat: response.data.results[0].geometry.location.lat, | |
lng: response.data.results[0].geometry.location.lng, | |
formatted_address: response.data.results[0].formatted_address | |
} |
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
const axios = require('axios') | |
const encodedAddress = encodeURIComponent('Av. Insurgentes Sur 601, Ciudad de México') | |
// console.log(encodedAddress) => Av.%20Insurgentes%20Sur%20601%2C%20Ciudad%20de%20M%C3%A9xico | |
const geocodeURL = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}` | |
axios.get(geocodeURL) | |
.then(response => { | |
if (response.data.status === 'ZERO_RESULTS') { | |
throw new Error('Unable to find that address') |
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
const request = require('request') | |
const geocodeAddress = (address, callback) => { | |
// console.log(encodedAddress) => Av.%20Insurgentes%20Sur%20601%2C%20Ciudad%20de%20M%C3%A9xico | |
const encodedAddress = encodeURIComponent(address) | |
request({ | |
url: `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`, | |
json: true | |
}, (error, response, body) => { | |
if (error) { |
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
async function name ([param[, param[, ... param]]]) { | |
// statements | |
} | |
async function fetchCountriesWithStates() { | |
const countries = await fetchCountries() | |
const _states = await fetchStates() | |
return countries.map(country => ({ | |
...country, |
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
function greet() { | |
name = 'Hammad'; | |
return function () { | |
console.log('Hi ' + name); | |
} | |
} | |
greet()(); // logs 'Hi Hammad' |
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
function greet() { | |
name = 'Hammad'; | |
return function () { | |
console.log('Hi ' + name); | |
} | |
} | |
greet(); // nothing happens, no errors | |
// the returned function from greet() gets saved in greetLetter |
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
function grandFather () { | |
var name = 'Oscar' | |
// like no es accesible aqui | |
fucntion parent () { | |
// name es accesible desde aqui | |
// like no es accesible desde aqui | |
function child () { | |
// nivel mas profundo del scope | |
// name tambien es accesible desde aqui | |
var likes = 'React' |
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
executionContextObject = { | |
'scopeChain': {}, // contiene su propio objeto variable y otros objetos variables de los contextos | |
'variableObject': {}, // contiene argumento de funciones, variables internas y declaraciones de funciones | |
'this': valueOfThis | |
} |
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
'scopeChain': { | |
// contiene su propio objeto variable y otros objetos de los contextos de ejecución padre | |
} |