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

221
Views
what's the difference between using then in argument and not

what's the difference between these two promises one is used in argument other outisde , which one is preferred

fetch(API_URL + "films")
  .then(response => response.json())
  .then(films => {
    output.innerText = getFilmTitles(films);
  })
  .catch(error => output.innerText = ":(")

fetch(API_URL + "films")
  .then(response => 
    response.json()
      .then(films => {
        output.innerText = getFilmTitles(films);
      }))
  .catch(error => output.innerText = ":(")
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is probably opinion based. I think the first one is preferred because you won't end up with nested promises and should be easier to read.

To make it more obvious:

fetch(API_URL + 'films')
  .then(response => response.json())
  .then(films => {
    output.innerText = getFilmTitles(films);
  })
  .catch(error => output.innerText = ':(');

vs

fetch(API_URL + 'films')
  .then(response => response.json()
    .then(films => {
      output.innerText = getFilmTitles(films);
    })
    .catch(error => output.innerText = ':(')
  );

The number of indentation of the second way would grow while the number of indentations in the first approach is fixed.

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!