Hello to all my community members. I have been stuck in this function I can't find any way to resolve this problem. I have been working as a jr. developer in a reputable mobile app development firm. Can anyone suggest me app developer who can help with this problem? Thanks!
function square(num, callback) {
if (typeof callback !== 'function') {
throw new TypeError(`Callback must be a function. Got: ${typeof callback}`);
}
// simulate async operation
setTimeout(() => {
if (typeof num !== 'number') {
// if an error occurs, it is passed as the first argument to the callback
callback(new TypeError(`Expected number but got: ${typeof num}`));
return;
}
const result = num * num;
// callback is invoked after the operation completes with the result