Explain what is happening in the code snippet?

  • 0
    function loginUser(email, password, callback) {
        setTimeout(() => {
            console.log("Now we have the data");
            callback({ userEmail: email });
        }, 3000);
    function getUserVideos(email, callback) {
        setTimeout(() => {
            callback(['video1', 'video2'])
        }, 1000)
    const user = loginUser('[email protected]', 123456, cb => {
        getUserVideos(cb.userEmail, (videos) => {

    As I understand it:
    1) at the entry point const user = loginUser in the callback function loginUser is passed arrow function
    2) the function loginUser
    is launched 3) after 3 seconds console.log ("Now we have the data");
    4) and then the callback function is run with an object as an argument
    5) when you run callback , the first thing to do is console.log (cb);

    and here it is not clear to me ...
    • what happens when a function is passed to the console for output? How is it that, as a result, in the console I see {userEmail: '[email protected]'} ?
    • and from where in the line getUserVideos (cb.userEmail, (videos) = & gt; { takes the property userEmail , if the functions cb nobody assigned it?
    JavaScript Anonymous, Jan 12, 2020

  • 1 Answers
  • 0
    You send an email to kalbek:

    callback ({userEmail: email});

    In the console log you output the object, the calbek argument, the same one that was passed above:

    console.log (cb);
    Dominic McCormick

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!