Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!