You will need to use a Promise or a callback function.. Here is an example how to implement the function using a promise:
function userExists(userID) {
   return new Promise(function(resolve, reject) {
       connection.query(query, function(error, results, fields) {
           resolve(results.length > 0);
       });
   }
}
userExists(1).then(function(result) {
  // Here result will be either true or false.
}
You probably can use ES6 syntax if you are running node so you can also write
const userExists = userID => new Promise((resolve, reject) => {
   connection.query(query, (error, results, fields) => {
       resolve(results.length > 0);
   });
});
userExists(1).then(result => {
    console.log(result);
});
EDIT:
If you for some reason needed to implement this using a callback function here is how you would do it.. Use of Promises are preferred though.
const userExists = (id, callback) => {
    connection.query(query, (error, results, fields) => {
        callback(results.length > 0);
    });
}
userExists(1, result => {
    console.log(result);
});