I have one concern about javascript callback function. What I understood is callback function should allow other statements to proceed if it takes time. So I have created one custom callback function to check but I'm not getting expected result. Am I doing wrong anything here?
function test(param1,param2,cb){
if(typeof(cb) === 'function') return cb(param1,param2)
else console.log('im not a func');
}
function calbackFunc(a,b){
console.log('Hi i am '+a+' '+b);
}
setTimeout(function timeout(){
console.log('timeout')
},0);
test('callback','function',calbackFunc);
console.log('console');
Output
"Hi I am callback function"
"console"
"timeout"
As per the callback function, 'console' should come first. but it's not happening. Like setTimeout is working fine. Then why my custom callback function behaving like setTimeout.