1

Can anyone explain to me what is going here?

I have been learning node and callbacks and I am kind of getting the concept but can use some more details.

So in function "myCallback" there is a log to console but in "usingItNow" there is no log to console and the result are "from myCallback From Using it" in the console.

How is it I do not need something like return in usingItNow?

Is this a proper representation for usingItNow if it were not a callback? var usingItNow = 'From Using it'

Can someone post some links to some good tuts?

Is usingItNow proper camelcase or should it be usingItnow?

var myCallback = function(data) {
    console.log('from myCallback ' + data);
};

var usingItNow = function(callback) {
    callback('From Using it');
};

usingItNow(myCallback);
1

1 Answer 1

3

In your code: usingItNow(myCallback);

You are invoking the function usingItNow and passing it function myCallback.

Inside usingItNow you are executing your parameter callback by doing this callback('From Using it') you are essentially doing myCallback('From Using it') because callback is equal to myCallback.

You don't need to return anything because myCallback is doing the logging.

Your camel case is fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I actually ran out and picked up Sams Teach yourself node. The 4th chapter does a good job explaining as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.