I am here again with a new topic, an interesting one it is. Welcome once again to my 100days of code challenge.I am discussing callbacks today.
Before I learnt about callbacks up till date, I believe a function can only take strings or numbers as arguments, I was wrong until I learnt about callbacks.
So What Are Callbacks?
Callbacks are functions passed into another functions as arguments. They are called back(hence the name callbacks) inside their accepting functions.
A function without a callback can be written as below.
function callMyName(name) {
console.log(`hello ${name}`);
};
When the above function is called and a string argument is passed, it prints out something like 'hello charles'.
There is another way this function above can be written and that's with the use of callbacks. This code below explains it.
function getUserInput(name, callback){
callback(name);
};
function callmyname(name){
console.log(`hello ${name}`);
};
Invoking getUserInput("Ade", callmyname);
Prints "hello Ade"
Congratulations @abdulganiy! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Congratulations @abdulganiy! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @hivebuzz: