Is it possible to return a value inside a callback, without another callback? [duplicate]

0

Well, I have a function that returns a value for a callback, but I wanted it to return without this callback, is it possible?

Function in question:

function getProfile(id, fn) {
    var sql = "SELECT * FROM profiles WHERE ID in ('" + id + "')";
    con.query(sql, function (err, result) {
        if (err) throw err;
        fn(result[0]);
    );
}

Code in practice:

var userData = getProfile(123, function(result) {
    console.log(result);
});

I wanted the userData variable to not require callback.

    
asked by anonymous 31.08.2017 / 22:32

0 answers