Difficulty: Medium
When competing CSS declarations apply, what determines the cascaded value?
A DOM depth alone
B HTML source length
C Cascade precedence
D Selector spelling
Answer: C. Cascade precedence. The cascade compares declarations by precedence to choose a final value.
Among common CSS selectors, which usually has greater specificity?
A #menu
B nav
C .menu
D *
Answer: A. #menu. An ID selector has greater specificity than a class selector in the same cascade context.
During event bubbling, which direction does the event travel?
A Toward siblings
B Into stylesheets
C Across network layers
D Toward ancestors
Answer: D. Toward ancestors. Bubbling sends an event from its target toward ancestor elements.
How can code cancel a browser’s default action?
A stopPropagation()
B preventDefault()
C clearTimeout()
D JSON.parse()
Answer: B. preventDefault(). preventDefault cancels the event’s default action without stopping propagation.
Which JavaScript object represents eventual asynchronous completion?
A NodeList
B RegExp
C Promise
D Map entry
Answer: C. Promise. A Promise represents a result that may become available asynchronously.
How does async/await handle a promise result?
A Blocks entire browser
B Suspends async function
C Changes CSS cascade
D Cancels network access
Answer: B. Suspends async function. Await pauses its async function until the promise settles.
Which event fires after HTML parsing, before many resources finish loading?
A DOMContentLoaded
B load
C submit
D beforeunload
Answer: A. DOMContentLoaded. DOMContentLoaded fires after document parsing, without waiting for every resource.
Why may a browser send a CORS preflight using OPTIONS?
A Download a page
B Refresh cookies
C Negotiate CSS
D Ask permission for request
Answer: D. Ask permission for request. OPTIONS preflight asks whether a cross-origin request is allowed.
With a 304 response, what should a cache use?
A Resource was created
B Authentication is missing
C Use stored representation
D Server failed
Answer: C. Use stored representation. 304 says the representation is unchanged, so a cache can reuse its stored body.
For cache validation, which response header can identify a representation?
A ETag
B Content-Length
C Accept
D Origin
Answer: A. ETag. ETag provides a validator for comparing representation versions.
When Cache-Control: no-store is sent, what should caches do?
A Store indefinitely
B Do not store response
C Revalidate always
D Share across origins
Answer: B. Do not store response. No-store instructs caches not to store the response.
When comparing two web origins, which components matter?
A Path query and fragment
B Cookie and title
C Method body and status
D Scheme host and port
Answer: D. Scheme host and port. An origin consists of scheme, host, and port.
To allow credentialed CORS responses, which setting is required?
A Access-Control-Max-Age
B Access-Control-Expose-Headers
C Access-Control-Allow-Credentials
D Access-Control-Request-Method
Answer: C. Access-Control-Allow-Credentials. Access-Control-Allow-Credentials signals whether cross-origin credentials are allowed.
How does PUT commonly differ from POST?
A POST is always safe
B PUT replaces target state
C PUT only retrieves data
D POST cannot carry content
Answer: B. PUT replaces target state. PUT creates or replaces the target resource state; POST performs resource-specific processing.
Which JavaScript method adds a listener without inline HTML?
A addEventListener()
B querySelectorAll()
C setAttribute()
D JSON.stringify()
Answer: A. addEventListener(). addEventListener registers a handler through the DOM API.
CSS custom properties are read with which function?
A ref(–accent)
B use(–accent)
C get(–accent)
D var(–accent)
Answer: D. var(–accent). var() retrieves the value of a CSS custom property.
If padding counts toward declared width, which box setting helps?
A display inline
B overflow hidden
C box-sizing border-box
D position absolute
Answer: C. box-sizing border-box. Border-box includes padding and border within the declared dimensions.
When font-size uses em units, what is its reference?
A Root font size
B Parent font size
C Viewport width
D Pixel size
Answer: B. Parent font size. For the font-size property, em is relative to the parent font size.
Which status usually indicates authentication is required?
A 401
B 403
C 409
D 422
Answer: A. 401. 401 indicates missing or invalid authentication credentials.
How does HTTP 403 generally differ from a missing resource?
A Resource is missing
B Request succeeded
C Request is forbidden
D Server is redirecting
Answer: C. Request is forbidden. 403 means the server refuses the request, even if it understands it.
Why should a form control have an associated label?
A CSS generated content
B URL fragment only
C Placeholder color
D Associated label text
Answer: D. Associated label text. An associated label provides the control’s accessible name.
Which HTML element groups related form controls?
A datalist
B fieldset
C output
D picture
Answer: B. fieldset. Fieldset groups related form controls under one legend or purpose.
Valid JSON text becomes what kind of JavaScript value after parsing?
A JavaScript data value
B HTML element tree
C CSS declaration list
D HTTP response
Answer: A. JavaScript data value. JSON parsing converts text into a JavaScript value.
Which response header can allow a specified cross-origin origin?
A Content-Security-Policy
B Strict-Transport-Security
C X-Content-Type-Options
D Access-Control-Allow-Origin
Answer: D. Access-Control-Allow-Origin. Access-Control-Allow-Origin names the origin allowed to read the response.
Why should GET avoid changing server state?
A GET requires a body
B GET disables caching
C GET is defined as safe
D GET encrypts content
Answer: C. GET is defined as safe. GET is defined as safe because it is not intended to change server state.