Ads 468x60px

Labels

Friday, November 11, 2022

callback in javascript in hindi | callback function in javascript synchronous vs asynchronous

callback in javascript in hindi | callback function in javascript synchronous vs asynchronous.

In this video you will be learn callback function in javascript .

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.

You can watch on video of Callback in javascript

now lets code to this
function printName(name) {
alert(`hi, ${name}`);
}

function useCallbackFun(callback) {
let name = prompt("Please enter your name.");
callback(name);
}

useCallbackFun(printName)

Now we create two function one is printName and seconod in useCallbackFun in this code we get the name in as argument in printName function and show to alert with text hi "name";


now in another way if we take time to get name then we used to this way to callback function

function printName(name) {
alert(`hi, ${name}`);
}

function useCallbackFun(callback) {
let name = '';
setTimeout(function(){
name = prompt("Please enter your name.");
callback(name);
},100)


}
useCallbackFun(printName)


Now let create another function with get odd and even number
as below is example :-


function isOdd(number) {
return number % 2 != 0;
}
function isEven(number) {
return number % 2 == 0;
}

function filter(numbers, fn) {
let results = [];
for (const number of numbers) {
if (fn(number)) {
results.push(number);
}
}
return results;
}
let numbers = [1, 2, 4, 7, 3, 5, 6];

console.log(filter(numbers, isOdd));
console.log(filter(numbers, isEven));


So, Like , subscribe, share, and support to keep us motivating.

Don't Forget to Follow me on all Social Network,
Twitter: https://twitter.com/rohitazad
Facebook: https://www.facebook.com/rohitazadmalik/
Stackoverflow: https://stackoverflow.com/users/1365428/rohit-azad-malik
LinkedIn: https://www.linkedin.com/in/rohitazad/
Github: https://github.com/rohitazad


Checkut t my chaanel in youtube :- https://www.youtube.com/c/AzadMalikRohit

0 comments:

Post a Comment