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

175
Views
What does "function(err, result)" in JavaScript

I don't understand what does this code do in JavaScript. Why it is used? As far as I know it is "callback" but how the data assigned to "result"? I've never seen an information explains that.

 var prompt = require('prompt');
 prompt.start();
 prompt.get(['name'], function (err, result) {
 console.log('  name: ' + result.name);
 });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you run a function that uses the callback, all you're doing is giving it another function for it to run when it is done. In your case, you are giving the prompt.get function the "function (err, result) {...}" function. When prompt.get is done and wants to return some result, it will call this function that you gave it. The function, as you can see, has parameters that can be passed to it (in your case, err and result). When it runs the callback (just like running any other function), it will give it parameters that are then exposed to the callback function you gave it.

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!