Quiz Space

Modern Application Development II · Quiz 2 · 1 Dec 2024 · September 2024 term

Question 16: Consider the below Vue component. Which of the following…

Question 16

+3 marksOne or more correct options

Consider the below Vue component.

html
<template>
<div>
<button @click="setDarkMode">Dark Mode</button>
<button @click="setLightMode">Light Mode</button>
</div>
</template>
<script>
export default {
data() {
return {
theme: localStorage.getItem('theme') || 'light'
};
},
methods: {
setDarkMode() {
this.theme = 'dark';
localStorage.setItem('theme', 'dark');
},
setLightMode() {
this.theme = 'light';
localStorage.setItem('theme', 'light');
}
}
};
</script>

Which of the following statement(s) is/are correct about the behavior of the above component?

Select all that apply.

  1. A

    The theme will persist across page reloads because it is stored in localStorage.

  2. B

    If the user opens a new tab, the theme will reset to 'light' in that new tab.

  3. C

    The theme will reset to 'light' every time the page is refreshed.

  4. D

    The theme will be shared across all open tabs, as localStorage is accessible across tabs of the same origin.

Show answer

Correct answers

  • A

    The theme will persist across page reloads because it is stored in localStorage.

  • D

    The theme will be shared across all open tabs, as localStorage is accessible across tabs of the same origin.

Question 16 of 16 in the IIT Madras BS Modern Application Development II (MAD 2) Quiz 2 paper sat on 1 Dec 2024, in the September 2024 term (IIT M DIPLOMA AN EXAM QDD2 01 Dec 2024). It carries 3 marks.

More questions from this paper

  1. Q1Consider the below JavaScript program. What will be the output of the above program?
  2. Q2Consider the below Vue component. What will be displayed in the <p> element, after the button with text “Change Message…
  3. Q3Consider the below JavaScript program. What will be the output of the program?
  4. Q4Consider the following HTML with Vue 2 CDN attached. What will be printed in the browser console ?
  5. Q5Consider the JavaScript code snippet below. What will be logged to the console?
  6. Q6Consider the below JavaScript program. What will be the output of the above program?
  7. Q7Consider the JavaScript code below. What will be the order of logs in the console?
  8. Q8In Vuex, what is the purpose of mutations?
  9. Q9Consider the below JavaScript program. What will be the output of the above program?
  10. Q10Consider the below Vuex implementation. After the user logs in with a token and refreshes the page, what will happen to…
  11. Q11Consider the following HTML, which includes Vue 2 and Vue Router 3 CDN links. Given this router setup, which of the fol…
  12. Q12Consider the following HTML, which includes Vue 2 and Vue Router 3 CDN links. What will be the final-rendered output in…
  13. Q13Which of the following is/are the use cases of watchers in Vue.js?
  14. Q14Which of the following statement(s) accurately describe the relationship between system state and application state?
  15. Q15Which of the following statement(s) is/are true about Vue.js components?