Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Variable is turning (intermediate value) at return statement while it is corrent inside of the function

I get stuck on a async function that is changing it's value through the executing. This function makes call to "openlibrary", that takes isbn number from the function parameter. So the call to the library is successful, and fetch returns a book object. I also print that parameter before return and it's still correct, until the return statement..

Why is that value turning (intermediate value) at the second argument of the Book class constructor?

class Book {
  constructor(title, authors, isbn, id) {
    this.title = title
    this.authors = authors
    this.isbn = isbn
    this.id = id
  }
}

const searchByISBN = async (isbn) => {
  const url = `https://openlibrary.org/api/books?bibkeys=ISBN:\
${isbn}&jscmd=details&format=json`
  const req = await fetch(url).catch(e => {
    // Request failed
    console.debug(e)
    return null
  })

  const data = await req.json()
  console.dir(data)
  // No book with given isbn has been found
  if (data[`ISBN:${isbn}`] === undefined)
    return false
  console.debug(isbn)
  return new Book(data[`ISBN:${isbn}`].details.title,
                  data[`ISBN:${isbn}`].details.authors.map(a => a.name),
                  isbn, books.length)
}

...
// Inside some async function or browser console
book = await searchByISBN('1234567890')
...

Console output:

Object { "ISBN:1234567890": {…}
1234567890
Uncaught (in promise) TypeError: data[("ISBN:" + (intermediate value))].details.authors is undefined
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

"Hello fellow being that shares the same plane of existence" - Rem. I think the problem might actually be with the ISBN you are trying out!

When I take a look at the JSON provided with this link: https://openlibrary.org/api/books?bibkeys=ISBN:1234567890&jscmd=details&format=json it doesn't show any authors. So your code is most likely confused about why there are no authors after being asked to retrieve the author 😔

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda