Web Development MCQs

100 MCQs  (Page 6 of 10)

What is the difference between the DOMContentLoaded and load events?
DOMContentLoaded waits for images
load fires first
DOMContentLoaded fires when the HTML is parsed; load waits for all resources, such as images and stylesheets
They are identical
Which string is valid JSON?
{'name': 'Karachi', 'temp': 35}
{"name": "Karachi", "temp": 35,}
{name: "Karachi", temp: 35}
{"name": "Karachi", "temp": 35}
What happens with fetch('/api/missing') when the server responds with 404?
The promise resolves normally, with response.ok set to false; fetch rejects only on network failure
It retries automatically
The promise rejects with an error
It throws a SyntaxError
What is a closure in JavaScript?
A function bundled with references to the variables of the scope where it was created, even after that scope has finished
A function that closes the browser
A sealed object
A completed promise
What does async/await do?
It lets asynchronous promise-based code be written in a synchronous style; await pauses the async function, not the whole thread
It replaces promises with callbacks
It makes JavaScript multithreaded
It blocks the browser while waiting
What is TypeScript?
A new browser engine
A server-side database
A typed superset of JavaScript that compiles (transpiles) to plain JavaScript
A CSS framework
What does document.querySelectorAll('.temp') return?
A live HTMLCollection
A static NodeList of all the matching elements
An array of strings
Only the first matching element
What is the difference between innerHTML and textContent?
textContent parses HTML
innerHTML parses its value as HTML (an XSS risk with untrusted data); textContent treats it as plain text
innerHTML escapes all tags
They are identical