Home / Past papers / MAD2 Quiz 1 / this paper

```
{{ message }} for interpolation
```
```html v-bind:title="msg" ``` for binding attributes

```html v-on:@click="doSomething" ``` for click event binding

```html <input v-model="inputValue"></input> ``` for two-way binding

Consider the following JavaScript code:
```javascript
let employees = [
{ name: "Rahul", age: 28 },
{ name: "Priya", age: 24 },
{ name: "Amit", age: 32 }
];
employees.sort((a, b) => a.age - b.age);
console.log(employees.map(e => e.name).join(" - "));
```
What will be printed on the console?
Consider the following JavaScript code snippet.
```javascript
const users = [
{ name: "Amit", age: 25 },
{ name: "Bhavna", age: 20 },
{ name: "Chirag", age: 30 },
];
const names = users
.filter((u) => u.age >= 25)
.map((u) => u.name.toUpperCase())
.sort();
console.log(JSON.stringify(names));
```
What is logged on the console?
Consider the following JavaScript code snippet.
```javascript
let subject = "Dog";
function camera() {
let subject = "Deer";
function click() {
console.log(`clicked picture of ${subject}`);
}
subject = "Cat";
return click;
}
let cameraPicture = camera();
cameraPicture();
```
What is logged to the console?
Match the following Vue 2 directives in Column A with their correct functionality in Column B: | Column A | Column B | |---|---| | 1. v-bind | A. Creates two-way data binding between form inputs and Vue data properties | | 2. v-model | B. Conditionally shows or hides elements using CSS display property | | 3. v-on | C. Binds HTML attributes or component properties to Vue data expressions | | 4. v-show | D. Attaches event listeners to DOM elements for handling user interactions | | 5. v-cloak | E. Prevents the flash of un-compiled template content before Vue initializes |

Consider the following HTML, with the correct Vue 2 CDN links included
```html
<body>
<div id="app">
<p>Coffee</p>
<button @click="orderCoffee">Order</button>
<p>Total Cost: {{totalCost}}</p>
<p>Order Count: {{orderCount}}</p>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
totalCost: '0',
unitPrice: 25,
orderCount: 0
}
},
methods: {
orderCoffee() {
this.totalCost += this.unitPrice;
this.orderCount++;
}
}
})
</script>
</body>
```
What will be displayed for "Total Cost" and "Order Count" when the Order button is clicked three times?
Total Cost: 75, Order Count: 3

Total Cost: 02525, Order Count: 3

Total Cost: 252525, Order Count: 3

Total Cost: 0252525, Order Count: 3

Consider this nested loop is written in JavaScript:
```javascript
let result = "";
for (let i = 0; i < 2; i++) {
for (var j = 0; j < 2; j++) {
result += i + j;
}
}
console.log(result);
```
Which of the following statements is/are true?
The output is "0011".

The inner loop runs 2 times for each outer loop iteration.

The output is "0123"

The values are concatenated into a **string**, not added as numbers.

Consider the following HTML and JavaScript code.
HTML file
```html
<button id="btn">Click Me</button>
<script>
const btn = document.getElementById('btn');
btn.addEventListener('click', () => console.log('A'));
btn.onclick = () => console.log('B');
btn.addEventListener('click', () => console.log('C'));
btn.click();
</script>
```
Among the following console log statements, which ones will be logged when the code executes?
(Select **all** that apply, irrespective of the order.)
Consider the following HTML and JavaScript, assume Vue 2 CDN link to be already included.
index.html:
```html
<div id="app">
<p v-for="n in numbers">{{ n }}</p>
</div>
<script src="app.js" ></script>
```
app.js:
```javascript
var app = new Vue({
el: "#app",
data: { numbers: [1, 2, 3] },
});
app.data.numbers.push(4);
```
How many `<p>` elements will be rendered?
Consider the following JavaScript code snippet:
```javascript
const products = [
{ name: 'Laptop', price: 1200, category: 'Electronics', inStock: true },
{ name: 'Book', price: 25, category: 'Education', inStock: false },
{ name: 'Phone', price: 800, category: 'Electronics', inStock: true },
{ name: 'Pen', price: 5, category: 'Stationery', inStock: true },
{ name: 'Tablet', price: 600, category: 'Electronics', inStock: false }
];
const result = products
.filter(item => item.category === 'Electronics' && item.inStock)
.map(item => ({ ...item, discountedPrice: item.price * 0.9 }))
.filter(item => item.discountedPrice > 500);
console.log(result.length);
console.log(result[0].name);
```
What will be the output of the above code on the browser's console?
``` 3 Laptop ```

2 Laptop

1 Phone

2 Phone

Consider the below JavaScript program:
```javascript
const globalVar = 50;
const object1 = {
globalVar: 100,
method1: function() {
console.log(globalVar, this.globalVar);
return () => {
console.log(globalVar, this.globalVar);
}
}
}
const object2 = {
globalVar: 200,
method2: () => {
console.log(globalVar, this.globalVar);
return function() {
console.log(globalVar, this.globalVar);
}
}
}
const fn1 = object1.method1();
fn1();
const fn2 = object2.method2();
fn2();
```
What will be the output of the above program on the browser's console, if executed?
``` 50 100 50 100 50 undefined 50 undefined ```

``` 50 100 50 100 50 undefined 50 200 ```

``` 100 50 100 50 200 50 200 50 ```

``` 50 100 50 100 50 undefined 50 this ```

Consider the following JavaScript code:
```javascript
class Region {
constructor(region) {
this.region = region;
}
describe() {
return `${this.region} is a region.`;
}
}
class Country extends Region {
constructor(region, name) {
super(region);
this.name = name;
}
describe() {
return `${this.name} is in ${this.region}.`;
}
}
let r = new Region("Asia");
let c = new Country("Europe", "Germany");
let f = c.describe;
```
Which of the following statements are **true**?
Calling r.describe() prints "Asia is a region."

Calling c.describe() prints "Germany is in Europe."

Calling f() directly will still print "Germany is in Europe."

The Country class overrides both the **constructor** and the **describe()** method from Region.

The call to super (region) inside Country's constructor is **not required** to initialize this.region.

Consider the following JavaScript function definitions. Which of the following will correctly return the product of three numbers and handle the case where any parameter is undefined by treating it as 1?

```javascript
let multiply = (a, b, c) => {
a = a || 1;
b = b || 1;
c = c || 1;
return a * b * c;
}
```
```javascript
function multiply(a = 1, b = 1, c = 1) {
return a * b * c;
}
```
```javascript
let multiply = (a, b, c) => {
return (a ?? 1) * (b ?? 1) * (c ?? 1);
}
```
```javascript
const multiply = function(a, b, c) {
if(a === undefined) a = 1;
if(b === undefined) b = 1;
if(c === undefined) c = 1;
a * b * c;
}
```

If the user types "hi" into the input box, what happens on the page, choose the closest to correct?

Only `<p>` updates to "hi", but `<h2>` remains "Hello Vue".

Both `<p>` and `<h2>` update and display "h1".

Only `<h3>` changes to "HI", but `<p>` and `<h2>` remain unchanged.

Nothing updates at all.

Which Vue.js features are shown in the code?

Two-way data binding using v-model.

Use of a named `slot` inside a child component.

Passing values from parent to child using props.

Use of lifecycle hooks.
Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Based on the provided question paper for "Diploma Level: Modern Application Development II", the core topics, concepts, and principles revolve around Vue.js 2 (a progressive JavaScript framework for building user interfaces). Below is a structured summary of the key areas to focus on for the exam, along with a Mermaid knowledge graph to visualize the relationships between topics.
Text Interpolation:
{{ }} for dynamic data binding (e.g., {{ message }}).v-text directive (e.g., <span v-text="message"></span>).Directives:
v- (e.g., v-if, v-show, v-bind, v-on).Shorthand syntax:
v-bind:href → :hrefv-on:click → @clickValid Template Syntax Examples:
<div>{{ message }}</div><div v-html="rawHtml"></div><input v-model="inputValue"><button @click="handleClick">Click</button>v-if vs v-show: | Directive | Behavior | DOM Impact | Performance | |-----------|--------------------------------------------------------------------------|---------------------------|----------------------| | v-if | Toggles element presence in DOM based on condition (true/false). | Removes/adds element. | Higher (re-renders). | | v-show | Toggles display: none CSS property. | Always in DOM. | Lower (no re-render).|Example:
<div v-if="isVisible">Visible if true</div>
<div v-show="isVisible">Always in DOM, toggles display</div>v-bind)class, id, href) dynamically.class/style binding.Examples:
<!-- Bind class dynamically -->
<div :class="{ active: isActive, 'text-danger': hasError }"></div>
<!-- Bind inline style -->
<div :style="{ color: textColor, fontSize: fontSize + 'px' }"></div>v-on)click, submit)..prevent, .stop, .once).Example:
<button @click.stop="handleClick">Click Me</button>v-model)input, textarea, select) to Vue instance data.Example:
<input v-model="username" placeholder="Enter name">
<p>Hello, {{ username }}!</p>v-for)v-for.:key for performance optimization (unique identifier).Example:
<ul>
<li v-for="(item, index) in items" :key="index">{{ item }}</li>
</ul>| Feature | Computed Properties | Methods | Watchers |
|---|---|---|---|
| Use Case | Cached, reactive data | Generic functions (not cached). | Reactive to specific data changes. |
| Syntax | computed: { fullName() { ... } } | methods: { greet() { ... } } | watch: { dataProp(newVal) { ... } } |
| Performance | Efficient (cached until dependencies change). | Re-evaluates on every render. | Runs asynchronously. |
Key hooks (order of execution):
beforeCreatecreatedbeforeMountmountedbeforeUpdateupdatedbeforeDestroydestroyedUse Cases:
created: Fetch initial data.mounted: Access DOM elements.beforeDestroy: Clean up event listeners.Vue.component('my-component', { ... })).Props: Custom attributes for passing data to child components.
v-bind to pass props).String, Number, Array).Example:
Vue.component('child-component', {
props: {
message: String,
count: {
type: Number,
default: 0
}
},
template: '<div>{{ message }} ({{ count }})</div>'
});Example:
// In component A:
this.$emit('custom-event', data);// In component B: this.$on('custom-event', (data) => { ... }); ```
Vue CLI: Command-line tool for scaffolding Vue projects.
Key commands:
vue create my-projectvue add router (add Vue Router)Typical Project Structure:
src/
├── assets/ # Static files (images, CSS)
├── components/ # Reusable components
├── views/ # Route-level components
├── App.vue # Root component
├── main.js # Entry point
└── router.js # Vue Router configKey Concepts:
router-link: Navigation link (renders as <a>).router-view: Dynamic component rendering.:param (e.g., /user/:id).Example:
const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
{ path: '/user/:id', component: User }
];
const router = new VueRouter({ routes });Core Concepts:
Example Store:
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) { state.count++; }
},
actions: {
incrementAsync({ commit }) {
setTimeout(() => commit('increment'), 1000);
}
}
});Example:
axios.get('https://api.example.com/data')
.then(response => { this.data = response.data; })
.catch(error => { console.error(error); });v-model for two-way binding.Example:
<input v-model="email" @blur="validateEmail">
<span v-if="errors.email">{{ errors.email }}</span>While this exam is primarily Vue.js-focused, some questions (e.g., Q11) may involve basic JavaScript logic or array methods. Here are essential snippets:
javascript const names = ['Amit', 'Chirag', 'Bhavna']; const filtered = names.filter(name => name.toUpperCase().startsWith('A')); // Result: ['Amit'] ``javascript const user = { name: 'Amit', age: 25 }; const { name } = user; // name = 'Amit' ``javascript const greet = (name) => Hello, ${name}!; ``javascript fetch('https://api.example.com') .then(response => response.json()) .then(data => console.log(data)); ``javascript async function fetchData() { const response = await fetch('https://api.example.com'); const data = await response.json(); return data; } ``Practice Vue.js Syntax:
v-if, v-for, v-bind, and v-model.Understand Lifecycle Hooks:
created vs mounted).Master Component Communication:
$emit child → parent), and Event Bus.Vue Router & Vuex:
Debugging:
Review Official Docs:
Solve Practical Problems:
Build a to-do app with:
v-model, v-for).computed).watch or created hook).