How to create Call back function in Java Script.

Forums JavaScriptHow to create Call back function in Java Script.
Staff asked 1 year ago

.

krishna kukadiya replied 1 year ago

Answers (1)

Add Answer
krishna kukadiya Marked As Accepted
Staff answered 1 year ago

A callback function is one of JavaScript’s superpowers. It is the method through which JavaScript provides a function as an argument to another function. To perform an action, the callback function is invoked in the outer function. Arguments in JavaScript are values that are provided to function parameters. They are only available in the function to which they are provided when that function is invoked. Consider parameters to be variables that hold values in a function.

function greetings(username) {
  alert('Welcome ' + username);
}
function saveUserName(callback) {
  var name = prompt('Please enter your username.');
  callback(username);
}
saveUserName(greetings);

 

Subscribe

Select Categories