[{"id":"fullstackbeg-001","courseId":"fullstack-beginner","domain":"frontend","topic":"Render-blocking CSS","prompt":"An interviewer notes that a page shows nothing until a large stylesheet in the head has finished downloading, even though the HTML arrived quickly. Why does the browser wait?","hint":"Think about what the browser needs before it can know how any element looks.","source":"https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/Critical_rendering_path","interaction":{"type":"single"},"options":[{"id":"a","text":"The browser must download every image before painting anything","whyNot":"Images load in parallel and do not stop the first paint; the page can render with empty image boxes."},{"id":"b","text":"CSS is render blocking: the browser waits for the CSSOM before rendering","why":"Later rules can override earlier ones, so the browser cannot render content until all the CSS is received and processed into the CSSOM."},{"id":"c","text":"HTML parsing stops completely until the stylesheet has been executed","whyNot":"Stylesheets are not executed; it is scripts without async or defer that pause the HTML parser."},{"id":"d","text":"The server holds back the HTML until the stylesheet has been sent","whyNot":"The scenario says the HTML arrived quickly; the delay is on the browser side, not the server."}],"answer":"b","explanation":"Rendering needs both the DOM and the CSSOM. Because CSS rules can override each other, the browser blocks rendering until the CSS is complete.","concept":"Rendering needs both the DOM and the CSSOM. Because CSS rules can override each other, the browser blocks rendering until the CSS is complete.","rev":1,"kind":"scenario","takeaways":["CSS blocks rendering; keep critical CSS small and load it early."]},{"id":"fullstackbeg-002","courseId":"fullstack-beginner","domain":"frontend","topic":"Default button type in a form","prompt":"A sign-up form has a Show password button next to the password field. Clicking it toggles the field, but it also reloads the page and clears what the user typed. What is the fix?","hint":"Ask what a button inside a form does when no one says what kind of button it is.","source":"https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button","interaction":{"type":"single"},"options":[{"id":"a","text":"Move the click handler from onclick to an addEventListener call","whyNot":"How the listener is attached does not change the button's own default action of submitting the form."},{"id":"b","text":"Change the form's method from post to get","whyNot":"The form would still be submitted and the page would still navigate, just with the data in the URL."},{"id":"c","text":"Give the Show password button type=\"button\"","why":"A button in a form with no type is a submit button. type=\"button\" gives it no default action, so only the script runs."},{"id":"d","text":"Replace the button with a link styled to look like a button","whyNot":"A link is for navigation and would need extra work to be keyboard and screen-reader friendly; the real fix is the button's type."}],"answer":"c","explanation":"A button associated with a form defaults to type=\"submit\", so it submits the form when clicked. Buttons that do not submit need type=\"button\".","concept":"A button associated with a form defaults to type=\"submit\", so it submits the form when clicked. Buttons that do not submit need type=\"button\".","rev":1,"kind":"scenario","code":"<form action=\"/signup\" method=\"post\">\n  <input id=\"pw\" type=\"password\">\n  <button onclick=\"toggle()\">\n    Show password\n  </button>\n  <button>Sign up</button>\n</form>","takeaways":["Inside a form, a button without a type submits it: use type=\"button\" for anything else."]},{"id":"fullstackbeg-003","courseId":"fullstack-beginner","domain":"frontend","topic":"sessionStorage vs localStorage","prompt":"A checkout form saves a half-filled draft in sessionStorage. A user opens the same page in a second tab, and later closes the first tab. What happens to the draft?","hint":"One of the two storage areas is scoped to the tab as well as the origin.","source":"https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage","interaction":{"type":"single"},"options":[{"id":"a","text":"Both tabs share one draft, and it is kept until the browser is fully closed","whyNot":"That describes neither API: sessionStorage is per tab, and localStorage is not cleared when the browser closes."},{"id":"b","text":"The draft is shared by all tabs of the origin and is kept indefinitely","whyNot":"That is localStorage, which is partitioned by origin only."},{"id":"c","text":"The draft is lost on every page reload, even in the same tab","whyNot":"A page session survives reloads and restores of the same tab."},{"id":"d","text":"Each tab has its own copy, and closing the first tab clears that tab's data","why":"sessionStorage is partitioned by origin and tab; a new tab starts a new page session, and closing a tab ends its session and clears its data."}],"answer":"d","explanation":"localStorage is per origin and persists; sessionStorage is per origin and per tab, survives reloads, and is cleared when the tab closes.","concept":"localStorage is per origin and persists; sessionStorage is per origin and per tab, survives reloads, and is cleared when the tab closes.","rev":1,"kind":"scenario","takeaways":["sessionStorage: one tab, survives reload, gone on close. localStorage: whole origin, persists."]},{"id":"fullstackbeg-004","courseId":"fullstack-beginner","domain":"frontend","topic":"fetch and HTTP errors","prompt":"A junior developer's code shows a user profile even when the API answers 404, and the catch block never runs. What is the bug?","hint":"Ask when exactly the promise returned by fetch rejects.","source":"https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch","interaction":{"type":"single"},"options":[{"id":"a","text":"fetch resolves on HTTP error statuses, so the code must check res.ok","why":"fetch only rejects on network failures or bad requests; a 404 or 500 still resolves, so the code must check res.ok or res.status itself."},{"id":"b","text":"await does not work with fetch, so the promise must use then instead","whyNot":"await works with any promise, including the one fetch returns; then would behave the same way."},{"id":"c","text":"The catch block only catches errors thrown by render, not by fetch","whyNot":"A rejected fetch inside try would be caught; the issue is that a 404 does not reject at all."},{"id":"d","text":"The server must send a 200 status with an error field instead of 404","whyNot":"404 is the right status for a missing resource; the client is the one that should read the status."}],"answer":"a","explanation":"A fetch promise rejects only when the request cannot be made or the network fails. HTTP error statuses resolve normally and must be checked with response.ok or response.status.","concept":"A fetch promise rejects only when the request cannot be made or the network fails. HTTP error statuses resolve normally and must be checked with response.ok or response.status.","rev":1,"kind":"scenario","code":"try {\n  const res = await fetch('/api/me');\n  const user = await res.json();\n  render(user);\n} catch (err) {\n  showError(err);\n}","takeaways":["fetch does not throw on 404 or 500: always check response.ok."]},{"id":"fullstackbeg-005","courseId":"fullstack-beginner","domain":"frontend","topic":"CORS","prompt":"A front end at https://app.example.com calls an API at https://api.example.com. The call works in curl, but the browser console shows a CORS error. What fixes it properly?","hint":"Who enforces the rule, and who has to grant the permission?","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS","interaction":{"type":"single"},"options":[{"id":"a","text":"Add mode: 'no-cors' to the fetch call so the browser skips the check","whyNot":"no-cors does not grant access; it gives an opaque response the script cannot read, so the data is still unavailable."},{"id":"b","text":"The API responds with an Access-Control-Allow-Origin header for that origin","why":"The browser enforces CORS and only exposes a cross-origin response when the server's headers allow the calling origin."},{"id":"c","text":"Send an Origin header from the front end that matches the API's domain","whyNot":"The browser sets the Origin header itself; a script cannot spoof it to bypass the check."},{"id":"d","text":"Switch the request from GET to POST, which is not covered by CORS","whyNot":"POST is also subject to CORS; the response still needs the right Access-Control-Allow-Origin header."}],"answer":"b","explanation":"CORS is enforced by the browser, but the permission comes from the server: the response must include Access-Control-Allow-Origin for the calling origin (and any preflight must be answered).","concept":"CORS is enforced by the browser, but the permission comes from the server: the response must include Access-Control-Allow-Origin for the calling origin (and any preflight must be answered).","rev":1,"kind":"scenario","takeaways":["CORS errors are fixed on the server with response headers, not in the client code.","curl works because only browsers enforce CORS."]}]