
01
Promise()
Takes two functions as arguments,
resolve()
, and reject()
function getWeather() { return new Promise(function(resolve,reject){ }) } let promise = getWheather() console.log(promise)
We use promises when we need to wait for information or data
02

The data can be pased thru resolve()
into a function using then()
function getWeather(){ return new Promise(function(resolve,reject){ resolve('Sunny') }) } const promise = getWeather() promise.then(function(data){ console.log(data) })
03
The same would work for reject()
, if we pass data into the second argument
function getWeather() { reuturn new Promise(function(resolve,reject){ // resolve('Sunny') reject('error' ) }) } const promise = getWeather() promise.then(function(data){ console.log(data) },function(rejectData){ console.log(rejectData) } )

04
A Promise
works well with async code, or data not yet recieved, **Note
you can call the function getWeather
directly when it returns a promise, and
we can pass other functions
into then and the argument is automatically passed in
function getWeather() { return new Promise(function (resolve, reject) { console.log('...waiting') setTimeout(() => { resolve('Cloudy') }, 90) }) } function weatherSymbols(weather) { if (weather == 'Cloudy') { console.log('☁️') } } getWeather().then(checkWeather)

05 Console
console.log('1')
Promise()
Takes two functions as arguments,
resolve()
, and reject()
function getWeather(){ return new Promise(function(resolve, reject )) }