Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

What is callback in js

// What is callback functions in js

// Lets make a function

// Putting parameter in it "callback"
function func1(callback) {
  console.log(callback); // Log 'callback'; And now our parameter callback is a function and we can call it from our func1 and this is what callback is
  hello();
}

// Making one more function to print hello world in console
function hello() {
  console.log("Hello world");
}

func1(hello); // Call func and give hello function as a arguement; Yes we can give function as arguement

// func1(hello()); // This is wrong way to give function as arguement
 
PREVIOUS NEXT
Tagged: #What #callback #js
ADD COMMENT
Topic
Name
6+8 =