Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda