Javascript Callbacks

Code Snippets Callbacks


In this code snippet, we’ll learn about callbacks in Javascript.

Callbacks are nothing more than function pointers passed as an argument into another function to be then called from within that function.

This example might seem a bit useless but the concept of callbacks becomes much more useful when we start dealing with asynchronous behavior. Like for example when making an API calleventstimers, …


isNumber(5, logToConsole);

function logToConsole(text){

function isNumber(input, callback){
  if(typeof input == "number")
  	callback("It's a number.");
 	callback("Not a number.");

Resulting output:


Leave a Reply

Your email address will not be published.

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger