Question: I'm trying to work out the Coinbase Pro node.js API.

When running this:

```
const buyParams = {
  price: '100.00', // USD
  size: '1', // BTC
  product_id: 'BTC-USD',
};
authedClient.buy(buyParams, callback);

```

I have the following error `callback is not defined` 

So I'm trying to understand how does callback work exactly. 

What is the callback here exactly? If I understand well I need to define the callback which is a function but what would be the purpose of this function? I this because I need to wait for the answer from `authedClient` method? Or this something else?

Answer: 
`.buy` method will call provided callback when it finishes.  

You probably want to do something depending on the result.  

That's why you need that callback.
Typically, you use callback functions in order to be called when the functions finish his work. But why callbacks and not simply catch the return result of the function? Because of synchronous events.

Check out [here](https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced) and the following code to understand better the problem of async functions and why javascript programmers solve it by using callback functions

```js
function syncFunc() {
   return "finished!";
}

function asyncFunc() {
  setTimeout(() => {
    return "finished!";
  },1);
}

function asyncFuncWithCallback(callback) {
  setTimeout(() => {
    callback("finished");
  },1);
}

console.log(`syncFunc: ${syncFunc()}`);
console.log(`asyncFunc: ${asyncFunc()}`);
asyncFuncWithCallback((value) => {
     console.log(`asyncFuncWithCallback: ${value}`);
});
```