callbacks
by REPLY2SAGAR
JavaScript
function readFile(filePath, callback) {
setTimeout(() => { // Simulate a file read delay
const fileResult = "File content of " + filePath;
callback(null, fileResult);
}, 1000);
}
readFile("example.txt", (err, content) => {
if (err) {
console.error("Error reading file:", err);
} else {
console.log("Received file content:", content);
}
});