Why we Need CallBack Function in Js Why we Don't Simply Call Function in Main Function?

Why Doesn’t we call other function over callbacks function

function serverRequest(query, callback){
  setTimeout(function(){
    var response = query + "full!";
    callback(response);
  },5000);
}

function getResults(results){
  console.log("Response from the server: " + results);
}

serverRequest("The glass is half ", getResults);

SomeThing like this

function serverRequest(query){
  setTimeout(function(){
    var response = query + "full!";
    getResults(response);
  },5000);
}     
serverRequest("The glass is half");

That’s fine if you only ever want to do one very specific thing. What happens as soon as there are two things you might want to do? You need to write the whole function out again. Like function anotherServerRequest(.... Then what happens if you want it do another thing? function yetAnotherServerRequest(.... And so on.

As opposed to a function that makes a request to a server and does anything (you just have to pass it a function that does that thing)

Also, if you are curious, here’s some more read on callbacks: https://teamtreehouse.com/community/why-do-we-even-need-callbacks

Thanks that Help Me Out

Thanks :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: