All About School - The Complete Education Forum and Classifieds

Members Login
Username 
 
Password 
    Remember Me  
Post Info TOPIC: Any developer who can help me in this function recalling?


Newbie

Status: Offline
Posts: 4
Date: Dec 12, 2022
Any developer who can help me in this function recalling?
Permalink   
 


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

    callback(null, result);

  }, 100);

}

 

 

 



__________________
Page 1 of 1  sorted by
 Add/remove tags to this thread
Quick Reply

Please log in to post quick replies.

Tweet this page Post to Digg Post to Del.icio.us


Create your own FREE Forum
Report Abuse
Powered by ActiveBoard