Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Case Suggestion: function as argument #351

Open
lastarcher opened this issue Mar 1, 2024 · 0 comments
Open

Use Case Suggestion: function as argument #351

lastarcher opened this issue Mar 1, 2024 · 0 comments

Comments

@lastarcher
Copy link

function fetchData(url, callback) {
// Simulate an asynchronous operation, like fetching data from an API
setTimeout(() => {
const data = 'Sample data from ' + url;
callback(data); // Call the callback function with the data
}, 1000); // Simulate a 1 second delay
}

// Define a function that will act as the callback
function processData(data) {
console.log('Received:', data);
}

// Pass processData as a callback function to fetchData
fetchData('https://api.example.com', processData);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant