Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.
16 / 16 published solutions
Question 2 MSQ · 2.0 marks
Which of the following statements about JavaScript scope is/are correct in the browser?
6406536344607.
is function-scoped
6406536344608.
and
are block-scoped
6406536344609.
Variables declared with
are hoisted and initialized with
6406536344610.
variables can be declared without initialization
6406536344611.
Global variables are always attached to window (as a property)
Published solution
**1. Compare scope boundaries:** var is scoped to its containing function or script, rather than an ordinary brace block. let and const introduce block-scoped bindings.
**2. Distinguish creation from initialization:** let is unavailable in its temporal dead zone before initialization; const requires an initializer in an ordinary declaration. Top-level let/const bindings do not automatically become window properties.
**Answer: A, B — A and B.**
A: **Correct:** var does not gain a new scope from a normal block inside a function.
B: **Correct:** Both keywords respect block scope.
C: **Incorrect:** let bindings exist before their declaration but are not initialized to undefined during the temporal dead zone.
D: **Incorrect:** An ordinary const declaration without an initializer is a syntax error.
E: **Incorrect:** Global lexical let/const bindings are not window properties.
Which of the following statements about JavaScript functions is/are true?
6406536344612.
Every function in JavaScript is an object.
6406536344613.
Arrow functions have their own **“this”** binding
6406536344614.
Function declarations are **hoisted**.
6406536344615.
Function expressions assigned to variables are **hoisted** with their function
value.
Published solution
**1. Identify function objects and declarations:** JavaScript functions are callable objects. Function declarations are instantiated before ordinary execution of their containing scope.
**2. Compare arrows and expressions:** Arrows capture lexical this. A function expression is evaluated when its assignment executes; only its variable binding may be created earlier, without that function value.
**Answer: A, C — A and C.**
A: **Correct:** Functions are objects with callable behavior.
B: **Incorrect:** An arrow inherits this rather than creating its own receiver binding.
C: **Correct:** Ordinary function declarations are available before their source position in the containing scope.
D: **Incorrect:** The function-expression value is not assigned until execution reaches the expression.
**1. Read the explicit receiver:** obj1.show.apply(obj1) invokes show with this equal to obj1.
**2. Resolve the property:** this.a is therefore obj1.a=20. Neither obj2.a=10 nor the global a=3 is used.
**Answer: A — 20.**
A: **Correct:** The explicit receiver obj1 has a=20.
B: **Incorrect:** obj2 is not passed to apply.
C: **Incorrect:** The receiver has the requested property a.
D: **Incorrect:** The function reads this.a rather than the global identifier a.
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?
**1. Start with an empty stored cart:** The first load passes the name property "Laptop", not the whole object, into addItemToCart. It parses the previous JSON, pushes the name, and saves the updated JSON.
**2. Count loads:** Initial loading plus two refreshes executes the push three times. localStorage survives these reloads, leaving three copies of Laptop.
**3. Identify the returned type:** getCartItems returns localStorage.getItem directly, so the logged value is the JSON string ["Laptop","Laptop","Laptop"]. B shows the intended three-item content.
**Answer: B — Three Laptop names: ["Laptop","Laptop","Laptop"].**
**Convention note:** This assumes cart was absent before the initial load. The precise logged JavaScript value is a JSON string, not an array, because getCartItems omits JSON.parse; B is the intended content match.
A: **Incorrect:** An item is appended on every load.
B: **Correct:** It shows the three Laptop names accumulated across three executions.
C: **Incorrect:** The function receives only .name, and the code runs three times rather than once.
D: **Incorrect:** The .name expression is defined and equals Laptop.
Match the following storage mechanisms used in the browser with their correct characteristics.
Which of the following is the correct matching?
6406536344624.
1 → B, 2 → C, 3 → A
6406536344625.
1 → B, 2 → A, 3 → C
6406536344626.
1 → A, 2 → C, 3 → B
6406536344627.
1 → B, 2 → C, 3 → D
Published solution
**1. Match storage lifetime and purpose:** Session storage belongs to a browser-tab session, matching B. Token storage describes retaining authentication tokens, matching C.
**2. Match cookies:** Cookies can persist across sessions when configured with an expiry and are attached automatically to applicable HTTP requests, matching D. None of these mechanisms inherently encrypts stored values as A claims.
**Answer: D — 1→B, 2→C, 3→D.**
**Convention note:** “Token storage” is a purpose, not a distinct browser API or a guarantee of security. Cookie persistence depends on expiry settings; transmission depends on domain/path, Secure, SameSite and request credentials.
A: **Incorrect:** Cookie storage does not automatically encrypt its contents.
B: **Incorrect:** Session and token characteristics are mismatched, and automatic encryption is not inherent.
C: **Incorrect:** Session storage is not automatically encrypted and cookie storage is not defined merely as token storage.
D: **Correct:** It gives Session→B, Token→C and Cookie→D.
Consider the following Vue application with markup index.html and javascript file app.js.
index.html:
app.js:
What will be rendered by the browser **after 4 seconds**?
6406536344629.
total payable amount is 6000
6406536344630.
total payable amount is 8200
6406536344631.
total payable amount is 1800
6406536344632.
total payable amount is 7800
Published solution
**1. Pop datasets in reverse order:** The first three timer ticks consume (5000,30,4), then (3000,20,3), then (2000,10,2). Simple interest is \(P r t/100\).
**2. Add the computed interest values:** They are 6000,1800,400, so totalPayableAmount becomes \(6000+1800+400=8200\). The computed property is recalculated from the updated reactive inputs.
**3. Check the fourth tick:** The array is now empty; pop() returns undefined and accessing data[0] throws before another sum is added. The existing displayed total remains 8200.
**Answer: B — total payable amount is 8200.**
**Convention note:** The interval is not cleared when appData becomes empty, so it causes an error at the fourth tick. That error does not erase the previously rendered total. “After 4 seconds” assumes the successful timer updates have run normally.
A: **Incorrect:** 6000 is the total after only the first tick.
B: **Correct:** The three successful updates sum to 8200.
C: **Incorrect:** 1800 is only the second tick’s interest.
D: **Incorrect:** It includes the first two increments but omits the final 400.
What will be the output of the following program ?
6406536344633.
Undefined
6406536344634.
Modern Application Development 2
6406536344635.
Will throw syntax error
6406536344636.
None of these
Published solution
**1. Follow the prototype:** The object-literal __proto__:course sets student’s prototype to course, where courseName is defined.
**2. Destructure through ordinary property access:** Reading student.courseName can find an inherited property. The courseName binding therefore receives "Modern Application Development 2".
**Answer: B — Modern Application Development 2.**
A: **Incorrect:** Inherited properties are available to ordinary property access and destructuring.
B: **Correct:** The lookup reaches course.courseName through the prototype.
C: **Incorrect:** The object-literal prototype setter and destructuring syntax are valid.
D: **Incorrect:** The listed course-name output is correct.
What is the final value of **x**, logged on the console?
Published solution
**1. Separate the bindings:** op(x) declares a parameter named x, which shadows the outer let x=2. Both op() calls pass no argument, so each local parameter begins as undefined.
**2. Evaluate only the local arithmetic:** undefined×3 becomes NaN; adding 4 and subtracting 1 keep NaN. No assignment touches the outer binding.
**3. Read the final outer value:** console.log(x) therefore prints 2.
**Answer: 2.**
Which of the following best describes **UI State (Ephemeral State)** in frontend applications?
6406536344637.
It includes all data stored permanently in the database and is shared across
users
6406536344638.
It represents the complete system data such as users, products, and
transactions
6406536344639.
It refers to short-lived interface elements like loading indicators or selected
tabs
6406536344640.
It handles complex application logic and long-term session management
Published solution
**1. Define ephemeral UI state:** It describes short-lived interface conditions, such as whether a request is loading, which tab is selected or whether a menu is open. It is usually local to a view rather than permanent domain data.
**Answer: C — It refers to short-lived interface elements like loading indicators or selected .**
A: **Incorrect:** Permanent shared database records are domain/application data.
B: **Incorrect:** Users, products and transactions describe longer-lived system data.
C: **Correct:** Loading indicators and selected tabs are standard short-lived UI state.
D: **Incorrect:** This concerns broader application/session concerns rather than ephemeral interface conditions.
Given that HTTP is stateless, which approach is commonly used to manage application state
between the client and the server?
6406536344641.
Storing all state permanently in frontend memory across sessions
6406536344642.
Allowing the frontend to handle complex business logic and data storage
6406536344643.
Client or server maintaining state and explicitly exchanging it through
requests
6406536344644.
Eliminating state entirely from web applications
Published solution
**1. Interpret stateless HTTP:** A request does not automatically carry conversational state from a preceding request.
**2. Carry context explicitly:** Clients can send a session cookie, token or other identifier; the server can retrieve stored state, or the client can send the needed data directly. State is managed by the application and exchanged in requests.
**Answer: C — Client or server maintaining state and explicitly exchanging it through .**
A: **Incorrect:** Frontend memory alone does not persist through closing or reloading the application.
B: **Incorrect:** Client-side logic alone does not explain client–server state continuity.
C: **Correct:** It explicitly communicates the context needed to associate separate requests.
D: **Incorrect:** Stateless transport does not require stateless applications.
**1. Create separate closures:** Each outer() invocation creates its own count=0. c1 and c2 therefore retain independent counters.
**2. Apply postfix increment:** return count++ returns the old value, then increments. The first two c1 calls return 0 then 1; the first c2 call returns its separate initial value 0.
**Answer: D — 0, 1, 0.**
A: **Incorrect:** This would correspond to prefix increment rather than the shown postfix increment.
B: **Incorrect:** The second c1 call observes its retained incremented state.
C: **Incorrect:** c2 has a separate counter and does not continue c1’s count.
D: **Correct:** The outputs are 0,1,0.
**1. Fill the complete slot:** No parent content targets the named complete slot, so its fallback heading Learned DBMS is displayed.
**2. Fill the default slot:** The ordinary parent heading supplies Exploring Vue Js, replacing the default fallback Exploring Frontend.
**3. Check the last-slot syntax:** The parent incorrectly places v-slot:last on a slot element rather than a template or component. It does not provide a usable last-slot heading to this child; the displayed headings are Learned DBMS and Exploring Vue Js.
**Answer: C — Learned DBMS; Exploring Vue Js.**
**Convention note:** The slot element bearing v-slot:last is invalid slot-provision syntax and can generate a compiler warning. Proper named-slot provision uses a template with v-slot:last; the question’s key excludes the attempted last heading.
A: **Incorrect:** Exploring Backend is not supplied by either the component or parent.
B: **Incorrect:** This is Last Course is not provided by the code.
C: **Correct:** It shows the complete-slot fallback followed by the parent’s default-slot heading.
D: **Incorrect:** C matches the intended rendered headings.
What would be the end result at the end of execution of the code?
6406536344657.
5
6406536344658.
13
6406536344659.
8
6406536344660.
11
Published solution
**1. Create and increment the shared count:** createCounter(3) sets start=count=3. counter(2) takes the numeric branch, making count=5 and returning a=5.
**2. Capture temp in the returned inner function:** counter() receives undefined, takes the nonnumeric branch and captures temp=5. Its returned function is immediately invoked with true, resetting count to the original start=3.
**3. Add the results:** That invocation returns d=temp+count=5+3=8. The final expression is a+d=5+8=13.
**Answer: B — 13.**
**Convention note:** The last line evaluates a+d but does not explicitly call console.log. A browser console displays 13 as the expression result; an ordinary script would produce no printed log from that line alone.
A: **Incorrect:** 5 is only a, not the final sum.
B: **Correct:** The shared reset gives d=8, so the sum is 13.
C: **Incorrect:** 8 is only d, not a+d.
D: **Incorrect:** It does not account for the captured temp=5 plus reset count=3.
**1. Evaluate the methods on their instances:** d.info() reads type="Electronic" and returns Electronic device. m.info() uses its override, reading brand="Samsung" and type="Electronic", returning Samsung is a Electronic device.
**2. Detach the method:** x=m.info stores the function without binding m. Class methods run in strict mode; plain x() has this=undefined and throws TypeError on this.brand.
**3. Distinguish a constructor from an instance method:** d.constructor refers to class Device. Calling a class as an ordinary function without new throws; it does not return info text.
**Answer: A, B, C — A, B and C.**
A: **Correct:** The base instance’s info method returns the stated text.
B: **Correct:** The subclass override uses the stored brand and type.
C: **Correct:** The detached class method loses its instance receiver and throws TypeError.
D: **Incorrect:** Class constructors cannot be invoked as ordinary functions to obtain an info string.
Consider the following HTML and Vue component code carefully and answer the given sub-
questions.
File: index.html
File: script.js
When the
lifecycle hook is invoked, which of the following statements becomes
TRUE?
6406536344661.
The
element exists in the DOM but still contains {{ message
}}
6406536344662.
The **DOM** content already reflects the updated value **"Start A"**
6406536344663.
The
hook has already executed
6406536344664.
The **DOM** does not exist at all
Published solution
**1. Locate beforeMount:** Vue has prepared its rendering machinery but has not yet patched the mounted DOM. The original in-document p element still exists with its literal interpolation text.
**2. Distinguish data from DOM:** Changing message to Start A inside beforeMount changes component data before the initial render, but the original DOM is not already showing that rendered value during this hook.
**Answer: A — The original p element exists and still contains {{ message }}.**
A: **Correct:** The original in-DOM template element still contains the interpolation before the initial patch.
B: **Incorrect:** Start A appears after rendering/patching, not already at entry to beforeMount.
C: **Incorrect:** mounted runs after the initial mount, later than beforeMount.
D: **Incorrect:** The initial HTML elements exist even though Vue has not patched them yet.
**1. Update data before initial rendering:** beforeMount appends " A" to message, changing Start into Start A. The initial render therefore writes Start A into the p element.
**2. Apply the mounted hook’s direct DOM change:** It reads that text and appends " DOM", producing Start A DOM.
**3. Check for further reactive changes:** mounted changes innerText, not message. With no subsequent reactive update, the displayed text stays Start A DOM.
**Answer: D — Start A DOM.**
A: **Incorrect:** It omits the mounted hook’s explicit DOM suffix.
B: **Incorrect:** The code never appends B.
C: **Incorrect:** The code never appends B before the DOM suffix.
D: **Correct:** It includes the beforeMount A suffix and mounted DOM suffix.