Home / Past papers / MAD2 Quiz 1 / this paper

Consider the below JavaScript program.
```javascript
let x = 5;
(function () {
console.log(x);
let x = 10;
})();
```
What will be the output of the above program?
5

10

undefined

Reference Error

null

What is the output of this code?
```javascript
console.log(myVar);
console.log(myFunc());
var myVar = "hello";
function myFunc() {
return "world";
}
```
Consider the below JavaScript program.
```javascript
function outer() {
let count = 0;
return function inner() {
return ++count;
};
}
const counter1 = outer();
const counter2 = outer();
console.log(counter1());
console.log(counter1());
console.log(counter2());
```
What will be the output of the above program
Consider the 4 JavaScript code snippets given below.
Code Snippet 1:
```javascript
let x = 10;
const y;
```
Code Snippet 2:
```javascript
let { a: b } = undefined;
```
Code Snippet 3:
```javascript
const arr = [1, 2];
arr = [3, 4];
```
Code Snippet 4:
```javascript
const a = 10, b = 20;
(() => { return a + b; })();
```
Which of the above JavaScript code snippet(s) will throw an error?
Consider the below VueJS application.
```html
<div id="app">
<p>{{ counter }}</p>
<button @click="updateCounter">Click Me</button>
</div>
<script>
new Vue({
el: '#app',
data: {
counter: 1,
},
methods: {
updateCounter() {
this.counter *= 2;
},
},
});
</script>
```
What will the “p” tag display when the button with the text “Click Me” is clicked three times?
Consider the following JavaScript code snippet shown below.
```javascript
let length = 5;
function countLen(item){
console.log(this.length);
}
const data = [countLen, "Apple", length]
data[0]('Script')
```
What will be output on browser's console for the above JavaScript code?
Consider the following JavaScript code snippet shown below.
```javascript
var value = 50;
const mainObj = {
value: 42,
getValue: function() {
return this.value;
}
};
const nextObj = {
value: 100
};
const getValue1 = mainObj.getValue.bind() (nextObj);
const getValue2 = mainObj.getValue.bind(nextObj) ();
console.log(getValue1);
console.log(getValue2);
```
What will be output on browser's console for the above JavaScript code?
50 100

42 50

``` 100 100 ```

undefined 100

undefined 50

Consider the following JavaScript code
```javascript
let Tree = {
name: "Oak",
size: 5,
description: function (size) {
return `A ${this.size > 10 ? 'large' : 'medium'} ${this.name} tree.`;
}
};
const willow = {
name: 'Willow'
};
const returnedString = Tree.description.call(willow, 15);
console.log(returnedString)
```
What will be the output of the code?
Consider the following HTML with relevant Vue CDN link attached.
```html
<div id="app">
<div :class="{ active: isActive, 'text-danger': hasError }">
{{ message }}
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello!',
isActive: true,
hasError: false
}
})
</script>
```
Given the Vue.js application above, which classes will be applied to the div containing the message?
Consider the following Vue2 app and the index file given below.
index.html
```html
<body>
<div id="app">
<h4>{{ state }}</h4>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"
></script>
<script src="./script.js"></script>
</body>
</html>
```
script.js
```javascript
const app = new Vue({
el: '#app',
data: {
terminal: ['3', '2', '1'],
curr_status: ["arrived", "departed", "delayed"]
},
computed: {
state: () => {
return `The flight 103 has ${this.curr_status[1]} from terminal ${this.terminal[2]}.`
}
}
})
```
What will be the output on the browser?
Consider the following Vue App and the HTML document given below.
index.html
```html
<body>
<div id="app">
<my-comp>
<h3>Exploring Vue JS</h3>
<template v-slot:ongoing>
<h3>Learning App Dev 2</h3>
</template>
</my-comp>
</div>
<script src="./script.js"></script>
</body>
```
script.js
```javascript
const MyComp = {
name: 'my-comp',
props: ['tech'],
template: `<div class="container">
<slot name="complete"><h3>Learned DBMS</h3></slot>
<slot name="ongoing"></slot>
<slot>Exploring Frontend</slot>
</div>`
}
const app = new Vue({
el: '#app',
components: {
MyComp
}
})
```
What will be rendered on the browser for code setup given above?
Consider the following HTML with relevant Vue CDN link attached.
```html
<div id="app1">
{{ messageA }}
</div>
<div id="app2">
{{ messageB }}
</div>
<script>
const vm1 = new Vue({
el: '#app1',
data: {
messageA: 'Hello from App 1'
}
})
const vm2 = new Vue({
el: '#app2',
data: {
messageB: 'Hello from App 2'
}
})
vm1.messageA = 'Updated App 1';
</script>
```
After the code execution above, what will be displayed on the page?
Consider the following HTML with relevant Vue CDN attached.
```html
<div id="app">
<input v-model.number="price" type="number">
<input v-model.number="quantity" type="number">
<p>Total: {{ total }}</p>
<p>Last Updated By: {{ lastUpdatedBy }}</p>
</div>
<script>
new Vue({
el: '#app',
data: {
price: 10,
quantity: 1,
total: 10,
lastUpdatedBy: 'initial'
},
watch: {
price: {
handler(newVal) {
this.total = newVal * this.quantity;
this.lastUpdatedBy = 'price';
}
},
quantity: {
handler(newVal) {
this.total = this.price * newVal;
this.lastUpdatedBy = 'quantity';
}
}
}
})
</script>
```
If the user changes the price to 20 and then immediately changes the quantity to 2, what will be the final values of total and lastUpdatedBy?
Consider the following JavaScript Code.
```javascript
class Person {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello, my name is ${this.name}`);
}
static identify() {
console.log("I am a Person class");
}
}
const john = new Person("John");
```
Which of the following expression(s) will cause an error?
``` john.greet(); ```

``` Person.greet(); ```

``` john.identify(); ```

``` Person.identify(); ```

```javascript console.log(john.name); ```
Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Variable Declarations and Scoping
var, let, and constFunctions and Closures
this keyword and its contextObject-Oriented Programming in JavaScript
Error Handling
Directives
v-if vs. v-showv-model for two-way data bindingv-bind for dynamic class bindingVue Instance and Components
Data Binding and Methods
{{ }}Event Handling
@click and other event directivesHoisting and TDZ
let and const are hoisted but not initialized (TDZ).var are hoisted and initialized with undefined.Closures
Example:
function outer() {
let count = 0;
return function inner() {
return ++count;
};
}this Context
this refers to the object it belongs to.bind, call, and apply.Directives
v-if: Adds/removes elements from the DOM.v-show: Toggles visibility using CSS.v-model: Creates two-way data bindings on form input and textarea elements.Data Binding
{{ message }}:class="{ active: isActive }"Watchers
Example:
watch: {
price: {
handler(newVal) {
this.total = newVal * this.quantity;
}
}
}These summaries and graphs should help you understand the core topics and their relationships, making it easier to prepare for the exam.