Answers for "callback in js"

83

javascript callback

/*
A callback function is a function passed into another function
as an argument, which is then invoked inside the outer function
to complete some kind of routine or action. 
*/
function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);
// The above example is a synchronous callback, as it is executed immediately.
Posted by: Guest on March-05-2021
11

callback function js

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);
Posted by: Guest on May-27-2020
1

callback in js

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback , {
  var name = prompt('Please enter your name.');
  callback(name);
}}

processUserInput(greeting);
Posted by: Guest on October-19-2020
0

js callback function

const add = (num1, num2) => num1 + num2;

const result = (num1, num2, cb) => {
  return "result is:" + cb(num1, num2);
}

const res = result(12, 13, add);
Posted by: Guest on January-26-2021
1

javascript callback function

// Callback Example 1: note, fn=function
/* 
In JavaScript, callback fn is:

- a function based into another functions as an argument to be
	executed LATER
- would be a Synchronous OR Asynchronous callback.
- hint: 

	Synchronous: processing from top to bottom, 
	stop until current code finished.
        
	Asynchronous: no wait, process the next block if there
    
*/

let numbers = [1, 2, 4, 7, 3, 5, 6];

/* To find all the odd numbers in the array, 
you can use the filter() method of the Array object.
- The filter() method creates a new array with the elements that
pass the test implemented by a fn.
- The following test fn returns true if a number is an odd
number:   */


function isOddNumber(number) { //to be the callback fn
    return number % 2;
}

// callback fn passed into another fn by its reference, No ()
const oddNumbers = numbers.filter(isOddNumber);
console.log(oddNumbers); // [ 1, 7, 3, 5 ]
Posted by: Guest on February-12-2021
0

callback function js

function myDisplayer(some) {  document.getElementById("demo").innerHTML 
  = some;}function myCalculator(num1, num2, myCallback) {  
  let sum = num1 + num2;  
  myCallback(sum);}myCalculator(5, 5, myDisplayer);
Posted by: Guest on May-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language