Question 6
Consider the below javascript program, and predict the output assuming the variable “random_num” always has a value greater than 8.
Note: Math.random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive)
const num = "9";
new Promise((rej, res) => { const random_num = Math.floor(Math.random() * 10);
if (random_num == num) rej(random_num) else res(num + num);}).then( (msg) => console.log("Some Data Came"), (msg) => console.log("Some Data Lost")).then(data => { console.log("Data Sent"); return data;}).then(num => console.log(num));Some Data Came
Some Data Lost
Some Data LostSome Data Came
Data Sent
Data SentSome Data Came
Data Sent
undefinedSome Data Lost
Data Sent
undefinedSome Data Lost
undefined
Data Sent