Home / Past papers / MAD2 Quiz 1 / this paper
is function-scopedvar
and
are block-scopedlet ``` const ```
are hoisted and initialized with 
let undefined
variables can be declared without initialization``` const ```
What will be printed on the console?```javascript
var a = 3;
const obj1 = {
a: 20,
show: function () {
console.log(this.a);
}
};
const obj2 = { a: 10 };
obj1.show.apply(obj1);
```
The above code is initially loaded in the browser, and then the browser is refreshed two times. What will be the final output printed in the console?```javascript
function addItemToCart(item) {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
cart.push(item);
localStorage.setItem('cart', JSON.stringify(cart));
}
function getCartItems() {
return localStorage.getItem('cart') || [];
}
addItemToCart({ id: 1, name: 'Laptop' }.name);
console.log(getCartItems());
```
``` [] ```

``` ['Laptop', 'Laptop', 'Laptop'] ```

```
[{ id: 1, name: 'Laptop' }]
```
[undefined]
Which of the following is the correct matching?| Storage Type | Characteristic | | :---------------- | :-------------------------------------------------------------------------------- | | 1. Session Storage | A. Data automatically encrypts itself without developer intervention. | | 2. Token Storage | B. Data persists only until the browser/tab is closed. | | 3. Cookie Storage | C. Often used to store authentication tokens securely on the client side. | | | D. Data persists across sessions, typically stored on the client and sent with every HTTP request. |
app.js:
What will be rendered by the browser after 4 seconds?```html
<div id="app">
<h4>total payable amount is {{totalPayableAmount}}</h4>
</div>
<script src = "app.js"></script>
```
```javascript
const app = new Vue({
el: '#app',
data: {
principal: 0,
annualInterestRate: 0,
duration: 0,
totalPayableAmount: 0,
},
computed: {
simpleInterest() {
return (this.principal * this.annualInterestRate * this.duration) /
100
},
},
})
let appData = [
[2000, 10, 2],
[3000, 20, 3],
[5000, 30, 4],
]
let handler = setInterval(() => {
data = appData.pop()
app.principal = data[0]
app.annualInterestRate = data[1]
app.duration = data[2]
app.totalPayableAmount += app.simpleInterest
}, 1000)
```
```javascript
const course = {
courseName: 'Modern Application Development 2',
courseCode: 'mad2',
}
const student = {
__proto__: course,
studentName: 'Rakesh',
studentCity: 'Delhi',
}
const { courseName } = student
console.log(courseName)
```
What is the final value of x, logged on the console?```javascript
let x = 2;
function op(x) {
x *= 3;
x += 4;
x -= 1;
}
op();
op();
console.log(x);
```
What will be the output of the above program ?```javascript
function outer() {
let count = 0;
return function inner() {
return count++;
};
}
const c1 = outer();
const c2 = outer();
console.log(c1())
console.log(c1())
console.log(c2())
```
File: script.js
What will be rendered on the browser for the code setup given above ?```html
<div id="app">
<my-comp>
<h3>Exploring Vue Js</h3>
<slot v-slot:last>
<h3>Learning App Dev 2</h3>
</slot>
</my-comp>
</div>
```
```javascript
const MyComp = {
name: 'my-comp',
props: ['tech'],
template: `
<div class="container">
<slot name="complete">
<h3>Learned DBMS</h3>
</slot>
<slot>
Exploring Frontend
</slot>
<slot name="last"></slot>
</div>
`
};
const app = new Vue({
el: '#app',
components: {
MyComp
}
});
```
Learned DBMS Exploring Backend

Learned DBMS Exploring Vue Js This is Last Course

Learned DBMS Exploring Vue Js
What would be the end result at the end of execution of the code?```javascript
function createCounter(start) {
let count = start;
return function (step) {
if (typeof step === "number") {
count += step;
return count;
}
}
return (function () {
let temp = count;
return function (reset = false) {
if (reset) {
count = start;
} else {
count++;
}
return temp + count;
};
})();
}
const counter = createCounter(3);
let a = counter(2);
let d = counter()(true);
a + d;
```
Which of the following statements are TRUE?```javascript
class Device {
constructor(type) {
this.type = type;
}
info() {
return `${this.type} device`;
}
}
class Mobile extends Device {
constructor(type, brand) {
super(type);
this.brand = brand;
}
info(brand = "type") {
return `${this.brand} is a ${this.type} device`;
}
}
let d = new Device("Electronic");
let m = new Mobile("Electronic", "Samsung");
let x = m.info;
```
returns "Electronic device"``` d.info() ```
returns "Samsung is a Electronic device"``` m.info() ```
throws a runtime errorx()
returns "Electronic device"``` d.constructor() ```
File: script.js

lifecycle hook is invoked, which of the following statements becomes TRUE?``` beforeMount() ```
element exists in the DOM but still contains {{ message }}```html <p id="text"> ```
hook has already executed``` mounted() ```
element after the component is fully mounted and all statements in the
hook have executed?`<p>` ``` mounted() ```

Start A

Start A B

Start A B DOM

Start A DOM
Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here's a summary of the core topics, concepts, principles, and equations essential for the exam, followed by a knowledge graph.
This exam primarily focuses on JavaScript fundamentals, browser APIs, web application architecture, and the Vue.js framework.
Variable Declaration and Scope:
var: Function-scoped or global. Declarations are hoisted and initialized with undefined. Global var variables are attached as properties to the global object (e.g., window in browsers).let and const: Block-scoped. Declarations are hoisted but not initialized, residing in the "Temporal Dead Zone" until their definition. const requires immediate initialization and cannot be reassigned. let/const variables declared globally are not attached to the window object.Functions:
function name() {}) and function expressions (const name = function() {}).var assigned function expression hoists var name = undefined;).this binding; they lexically inherit this from their enclosing scope.this Keyword:
this depends on how the function is called.this typically defaults to the global object (window). In strict mode (implicitly for classes and modules), this is undefined.obj.method()), this refers to obj.Explicit Binding: Methods like call(), apply(), and bind() allow explicitly setting the this context.
func.apply(thisArg, [argsArray]): Calls func with thisArg as this and arguments provided as an array.Closures:
Prototypes and Classes (OOP):
__proto__): Objects inherit properties and methods from their prototypes. When a property is accessed, JavaScript traverses the prototype chain until it finds the property or reaches the end (null).class, extends, constructor, super()) for creating constructor functions and managing prototype-based inheritance, essentially syntactic sugar over the older prototype model.Destructuring Assignment:
Data Types and Operators:
typeof operator to check the type of a variable.undefined or NaN (Not-a-Number) typically result in NaN.JSON (JavaScript Object Notation):
JSON.parse(string): Converts a JSON string into a JavaScript object.JSON.stringify(object): Converts a JavaScript object into a JSON string.Web Storage:
localStorage: Stores data with no expiration date. Data persists even after the browser is closed. Data is origin-specific.sessionStorage: Stores data for the duration of a single browser session (i.e., until the browser tab or window is closed). Data is origin-specific.localStorage or cookies. Security considerations are paramount.HTTP Protocol:
UI State Management:
DOM Manipulation:
document.getElementById() and manipulating properties like innerText.Vue Instance:
new Vue({ ... }). The el property specifies the DOM element Vue will mount to.Data Reactivity:
data option defines the reactive state of a Vue instance/component. Changes to data properties automatically trigger re-renders of the template.Computed Properties:
computed option. These are functions that return a value based on reactive data. They automatically re-evaluate only when their reactive dependencies change, and their results are cached.Components:
data, methods, computed properties, and template.props: Used to pass data from a parent component to a child component.Slots:
<slot></slot>): Renders any content passed between the component's opening and closing tags in the parent. Can have fallback content.<slot name="name"></slot>): Renders specific content targeted by the v-slot:name directive in the parent. Can have fallback content.v-slot Directive: Used in the parent component's template to specify which content goes into which slot of the child component.Lifecycle Hooks:
beforeMount(): Called just before the component's template is rendered into the DOM. The reactive data is set up, but the actual DOM is not yet available.mounted(): Called after the component has been rendered into the DOM. The component's $el (the root DOM element) is now accessible. Direct DOM manipulation can be performed here.Template Syntax:
{{ propertyName }}: Text interpolation to display reactive data in the template.While the exam is primarily software-focused, one question involved a basic financial calculation:
Annual Interest Rate is typically given as a percentage (e.g., if the rate is 30%, use 30 in the formula, not 0.30).