Quiz Space

Modern Application Development II · End Term · 22 Dec 2024 · September 2024 term · Set QDF1

Question 7: Consider the following JavaScript code. The above code is…

Question 7

+3 marksOne correct option

Consider the following JavaScript code.

javascript
function addItemToCart(item) {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
cart.push(item);
localStorage.setItem('cart', JSON.stringify(cart));
}
function getCartItems() {
return JSON.parse(localStorage.getItem('cart')) || [];
}
addItemToCart({ id: 1, name: 'Laptop' }.name);
console.log(getCartItems());

The above code is initially loaded on the browser and then the browser is refreshed two times. What will be the final output?

  1. A

    []

  2. B

    ['Laptop', ‘Laptop’, ‘Laptop’]

  3. C

    [{ id: 1, name: 'Laptop' }]

  4. D

    [undefined]

Show answer

Correct answer

  • B

    ['Laptop', ‘Laptop’, ‘Laptop’]

Question 7 of 32 in the IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 22 Dec 2024, in the September 2024 term (IIT M FOUNDATION DIPLOMA AN EXAM QDF3 22 Dec 2024). It carries 3 marks.

More questions from this paper

  1. Q1Which of the following statements is true about closures in JavaScript?
  2. Q2Consider the below JavaScript program. What will be the output of the above program?
  3. Q3Consider the below JavaScript program. What will be the output of the above program?
  4. Q4Consider the below Vue app. What will happen if the following code is executed? app.user.name = “Dev”
  5. Q5Consider the below Vue component. What will happen when “this.isVisible = false” is executed?
  6. Q6Figure question
  7. Q8Which of the following is true regarding long polling?
  8. Q9What's the issue with this Vuex mutation? Assuming this mutation is part of vuex store.
  9. Q10Suppose you want the user data to only be accessible by an authenticated user. What security issue exists in this code?…
  10. Q11Given this Vue component structure: Which slot usage is correct?
  11. Q12Consider the following JavaScript code snippet. What will be the output on the console?
  12. Q13consider the following javascript code snippet. What will be the output sequence?
  13. Q14Which of the following best describes the difference between @cache.memoize() and @cache.cached() in Flask-Caching?
  14. Q15Consider the following Script embedded in an HTML document. Which of the following statement is correct, if the HTML do…
  15. Q16Which of the following statements is false when using the “async” and “await” keywords in JavaScript?
  16. Q17Consider the below JavaScript program. What will be the output of the above program?
  17. Q18Consider the below JavaScript program. What will be the output of the above program?
  18. Q19Which of the following statements about the beforeDestroy and destroyed lifecycle hooks in Vue is true?
  19. Q20Consider the following JavaScript code. What will be the output of the code snippet?
  20. Q21Which of the following statements is FALSE?
  21. Q22What will happen if a page includes this CSP header and the script attempts to load an external JavaScript file from ot…
  22. Q23Consider the below HTML document. What will be logged on the console, if the user opens the rendered web page in a brow…
  23. Q24Given the following Vuex store setup. Assuming the store is correctly binded with a Vue app, what will be the correct b…
  24. Q25Consider the following HTML with Vue CDN included? What will be logged on the console after the button is pressed?
  25. Q26Consider the following HTML with appropriate Vue 2 CDN link attached. What will be rendered in the <p> tag after the Li…
  26. Q27Consider the following HTML, which includes Vue 2 and Vuex CDN links. What will be rendered on the browser, if the fetc…
  27. Q28Consider the following Script embedded in an HTML document. What will be the output on console, if the HTML document is…
  28. Q29Consider the following Script embedded in an HTML document. What will be the output on console, if the HTML document is…
  29. Q30Consider the following Script embedded in an HTML document. Which of the following statements will throw an error on th…
  30. Q31Consider the following two HTML documents and the Vue app created in script.js file and select the correct option(s). i…
  31. Q32Consider the below Vue router configuration. Which of the following is a valid way to access the “id” parameter inside …