Why use javascript callbacks when cleaner syntax is available?

I'm trying to learn to use Node. So far, so good. But, being pretty new to JavasSript and I don't really get the point of using callbacks when a cleaner and more readable (at least to me) syntax is available.

Here's an example code to make my point clearer:

With a callback:

exports.create = function(req, res){
  new Todo({
    content    : req.body.content,
    updated_at : Date.now()
  }).save(function(err, todo, count){
    res.redirect('/');
  });
};

Without a callback:

exports.create = function(req, res){
  newtodo = new Todo({
    content    : req.body.content,
    updated_at : Date.now()
  });
  newtodo.save();
  res.redirect('/');
};

Both of these codes will save the new todo and redirect.

My preference goes to the second one, which I find easier to read, but maybe there's is a difference that I don't get. Is there a difference?

The short answer is: To avoid locking the user interface while an operation that takes time is finishing executing.

In your second example, if the save function makes an ajax call, you would have to make that a synchronous ajax call.

For the first one, you have a chance to handle error after the query is done. For the second one, you automatically assume that nothing bad will happen, and your query will always be successful, and users will always be redirected to somewhere after that.

It depends on your use case, if you dont want to show the error to the user, go with (2), otherwise go with (1). (2) is particularly useful when you only want to log an event, send email or do stuff that users (and/or you) dont even care if it fails. Most of the time, you will want to pick (1) as you need to display some sort of error to the end user instead of silently ignore errors