Question 25
Consider the below JavaScript program.
new Promise((resolve, reject) => { const num = 0.6; if (num > 0.5) { resolve(num); } else { reject(num); }}).then(data => { console.log("Step 1:", data); if (data > 0.75) { return data * 2; } else { return Promise.reject(new Error("Less than 0.75")); }}).then(data => { console.log("Step 2:", data); return data + 5;}).catch(error => { console.log("Step 3:", error.message); if (error.message === "Less than 0.75") { return 1; } else { throw error; }}) .then(data => { console.log("Step 4:", data); if (data === 1) { throw new Error("Fallback value"); } else { return data * 3; }}) .catch(error => { console.log("Step 5:", error.message); return "Error handled";
}).finally(() => { console.log("Step 6: Finally block executed");})What will be the output of the above program?
Step 1: 0.6
Step 2: 1.2
Step 4: 6.2
Step 6: Finally block executedStep 1: 0.6
Step 3: Less than 0.75
Step 4: 1
Step 5: Fallback value
Step 6: Finally block executedStep 1: 0.6
Step 2: 1.2
Step 3: Error
Step 4: 1
Step 5: Fallback value
Step 6: Finally block executedStep 1: 0.6
Step 3: Less than 0.75
Step 4: 1
Step 6: Finally block executed