MY #100 DAYS OF CODE CHALLENGE JOURNEY-DAY 14

in #coding6 years ago

IMG_20190224_083959.jpg

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"

Sort:  

Congratulations @abdulganiy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 3 years!

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:

The new SteemFest⁴ badge is ready
Vote for @Steemitboard as a witness to get one more award and increased upvotes!