5 questions · JavaScript · intermediate level
What does this output?
function counter() {
let count = 0
return {
increment: () => ++count,
decrement: () => --count,
value: () => count,
}
}
const c = counter()
c.increment()
c.increment()
c.decrement()
console.log(c.value())What is logged?
console.log('1')
Promise.resolve().then(() => console.log('2'))
console.log('3')This function should fetch user data. Spot the bug:
async function getUser(id) {
const res = fetch(`/api/users/${id}`)
const data = await res.json()
return data
}