Intermediate Interview Questions

What are semantic elements? Give examples.

Elements whose name describes their meaning: header, nav, main, article, section, aside, footer, figure, time. They improve accessibility, SEO and code readability compared with generic divs.

section vs article vs div?

  • <article>: self-contained content that makes sense on its own (blog post, comment, product card).
  • <section>: a thematic group of content, normally with a heading.
  • <div>: no meaning; only for styling or scripting hooks.

GET vs POST in forms?

GETPOST
data in the URL query stringdata in the request body
can be bookmarked and cachednot bookmarked or cached
length-limited, visible in historysuitable for large and sensitive data
for searches and filtersfor logins, sign-ups, payments

What do the defer and async attributes do?

Both download the script without blocking HTML parsing. defer runs scripts after parsing, in document order. async runs each script as soon as it is downloaded, in any order. Use defer for app code and async for independent scripts like analytics.

localStorage vs sessionStorage vs cookies?

localStoragesessionStorageCookies
Lifetimeuntil cleareduntil tab closesset by expiry
Size~5 MB~5 MB~4 KB
Sent to servernonowith every request
Usepreferences, cacheper-tab statesessions, auth (HttpOnly)

What is the purpose of the viewport meta tag?

<meta name="viewport" content="width=device-width, initial-scale=1"> makes mobile browsers use the real device width instead of a zoomed-out ~980px desktop width. Responsive CSS media queries depend on it.

What is the difference between srcset and the picture element?

srcset offers the same image at different resolutions and the browser chooses. <picture> lets you choose different images or formats by media query or type (art direction, AVIF/WebP fallbacks).