01. Consider the following code:
function Team(name) { this.name = name; }
Team.prototype.members = [];
var a = new Team("Red");
var b = new Team("Blue");
a.members.push("Ann");
console.log(b.members.length);
What does the console show?
a) undefined
b) 1
c) 0
d) A TypeError message
02. A page served from https://shop.example.com calls fetch("https://api.partner.net/rates"). The console reports that the response was blocked by CORS policy.
Which two statements are true?
(Choose two.)
a) The api.partner.net server must send an Access-Control-Allow-Origin header that permits the shop's origin
b) By default the page cannot read a response from a different origin, because the browser enforces the same-origin policy
c) Replacing fetch() with XMLHttpRequest avoids the restriction, because CORS applies to the Fetch API only
d) Adding mode: "no-cors" to the fetch() options lets the script read the rates from the response body
03. Consider the following code, where settings has never been declared:
if (typeof settings == undefined) {
settings = { theme: "light" };
}
The developer expects the block to create settings, but later code fails with a ReferenceError. Why does the block never run?
a) typeof throws a ReferenceError when its operand has never been declared
b) A block cannot create a global variable without the var keyword
c) typeof returns the string "undefined", which never equals the value undefined
d) == cannot compare a value against undefined; the test needs ===
04. A marketing site loads a full front-end framework and six plug-ins on every page, and pages take several seconds to become usable on mobile devices.
Which two changes are most likely to reduce load time without removing features users rely on?
(Choose two.)
a) Move every script element into the head so the scripts are cached sooner
b) Load non-critical scripts with defer so they do not block rendering
c) Fetch each plug-in synchronously with XMLHttpRequest for a predictable order
d) Minify and bundle the scripts so the browser downloads fewer, smaller files
05. A page's head contains these elements, in this order:
<script src="js/carousel.jquery-plugin.js"></script>
<script src="https://cdn.example.com/jquery.min.js"></script>
The console reports ReferenceError: jQuery is not defined, raised from the plugin file. What is the fix?
a) List the jQuery library element before the plugin element
b) Add async to both elements so the browser resolves the dependency
c) Host jQuery locally, because plug-ins cannot use a library loaded from a CDN
d) Give the plugin an absolute URL on the same CDN as jQuery
06. A loop runs 500 times and miscalculates only when i equals 437. A developer wants execution to pause at one line in the loop body on that iteration only, so every variable can be inspected in the browser's developer tools.
Which technique is most efficient?
a) A conditional breakpoint on that line with the condition i === 437
b) A debugger; statement on that line, resuming until i reaches 437
c) A console.log(i) call on that line, read after the loop ends
d) An alert(i) call on that line, so the script stops at each pass
07. Consider the following code:
var a = parseInt("12.7px");
var b = Number("12.7px");
var c = parseFloat("12.7px");
What are the values of a, b and c?
a) 13, NaN and 12.7
b) 12.7, NaN and 12.7
c) 12, 12.7 and 12.7
d) 12, NaN and 12.7
08. A store-locator page calls navigator.geolocation.getCurrentPosition(showStores, showError).
Which two statements about this call are true?
(Choose two.)
a) The location comes only from GPS, so computers without it always fail
b) If the user refuses, showError is called instead of showStores
c) The browser asks the user for permission before sharing a location
d) The call returns a position object that the next statement can read
09. A div with id panel contains a button with id save. A script attaches a handler with document.getElementById("save").addEventListener("click", saveForm); and later runs:
document.getElementById("panel").innerHTML += "<p>Draft saved</p>";
After that line runs, clicking the button no longer calls saveForm. Why?
a) Re-parsing the markup replaces the button with a new copy that has no listener
b) Listeners added with addEventListener() are removed whenever the document changes
c) The new paragraph moves the button out of the panel, so its clicks no longer reach the listener
d) innerHTML strips the onclick attribute that addEventListener() wrote into the button
10. A page loads stats.js, a self-contained analytics script that no other script depends on and that never touches the page's elements. It should download in parallel with HTML parsing and run as soon as it has downloaded, in any order relative to other scripts.
Which element and placement meet these requirements?
a) <script src="stats.js"></script> at the end of the body
b) <script src="stats.js" defer></script> in the head
c) <script src="stats.js" async></script> in the head
d) <script src="stats.js"></script> in the head