Quiz Space

Modern Application Development II · Quiz 2 · 16 Mar 2025 · January 2025 term

Question 9: Consider the following javascript code. When the function…

Question 9

+3 marksOne correct option

Consider the following javascript code.

javascript
async function fetchData() {
try {
const response = await fetch('https://api.example.com/data');
if (!response.ok) throw new Error('HTTP error');
const data = await response.json();
return data;
} catch (error) {
if (error.name === 'TypeError') {
return { status: 'network error' };
}
return { status: 'http error' };
}
}

When the function is called what will be returned if the server is unreachable?

  1. A

    { status: 'http error' }

  2. B

    { status: 'network error' }

  3. C

    undefined

  4. D

    The promise will remain pending

Show answer

Correct answer

  • B

    { status: 'network error' }

Question 9 of 16 in the IIT Madras BS Modern Application Development II (MAD 2) Quiz 2 paper sat on 16 Mar 2025, in the January 2025 term (IIT M DIPLOMA AN EXAM QDD2 16 Mar 2025). It carries 3 marks.

More questions from this paper

  1. Q1Figure question
  2. Q2Figure question
  3. Q3Figure question
  4. Q4Consider the below javascript program. What will be the output of the above program?
  5. Q5Consider the below javascript program. What will be the output of the above program?
  6. Q6Figure question
  7. Q7Consider the below Vue router setup. What will be the behavior when the user visits “/products/123/reviews”?
  8. Q8Consider the below Vuex setup. What will happen if the user dispatches the “addItemToCart” action to add a new item to …
  9. Q10Consider the following javascript code. What's logged?
  10. Q11Consider the following html with relevant vue cdn links added. If a user clicks rapidly twice (within 500ms), what will…
  11. Q12Consider the following html with relevant vue cdn links added. In the Vue application above, what will be the initial r…
  12. Q13Consider the below javascript program. What will be the output of the above program?
  13. Q14Consider the below Vue router setup. Note: Assume that the API “/api/users/userId” is operational and returns the user’…
  14. Q15Consider the below Vue.js application. What will be the visited pages history when the user navigates between pages and…
  15. Q16Consider the below Vue.js application. What will happen if the user submits the form and reloads the page?