Callback Function

Run Settings
LanguageJavaScript
Language Version
Run Command
// A function that simulates a long-running task using a timeout function fetchData(callback) { console.log("Fetching data... Please wait."); // Simulate a network request using setTimeout setTimeout(() => { console.log("Data fetched successfully!"); const data = { name: "Martins", age: 24 }; // Call the callback function with the fetched data callback(data); }, 2000); // 2-second delay to simulate async operation } // A callback function to handle the fetched data function displayData(data) { console.log("Displaying data:"); console.log(`Name: ${data.name}`); console.log(`Age: ${data.age}`); } // Call the function with the callback fetchData(displayData);
Editor Settings
Theme
Key bindings
Full width
Lines