var secret = "farted"
let location = 'Living room'
const literal = `I just ${farted} in the ${location}`
- strings
- object
- array
// example of STRINGS
const name = 'Erik'
const surname "Erikssson"
const fullName = `${name} ${surname}`
// Example of OBJECT and how to interact
const person = {
name: "Erik",
says: function(message) {
console.log('Erik says: ' + message)
}
}
// array
const brothers = ['erik', 'anton']
const first = brothers[0] // erik
const seconds = brothers[1] // anton
const howMany = brothers.length // 2
function add(a, b) {
return a + b
}
const multiply = (a,b) => a * b
function whatIsMyMonthlySalary(hourRate, hoursWorked) {
return multiply(hourRate, hoursWorked)
}
whatIsMyMonthlySalary(200, 160)
An application program interface (API) is a set of routines, protocols, and tools for building software applications. Basically, an API specifies how software components should interact. Additionally, APIs are used when programming graphical user interface (GUI) components.
http://api.weather.com/getWeatherByName?c=Stockholm
How to build the API you build functions that handle information and return data depending in input and or HTTP method ('GET', 'POST', 'DELETE').
A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved (e.g., a network error occurred).
const promise = fetch('url')
promise.then(response => {
// deal with response
})
https://javascript.info/async-await
There’s a special syntax to work with promises in a more comfortable fashion, called “async/await”. It’s surprisingly easy to understand and use.
async function getData() {
const weather = await fetch(url)
.then(res => res.json())
}