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?
| GET | POST |
|---|---|
| data in the URL query string | data in the request body |
| can be bookmarked and cached | not bookmarked or cached |
| length-limited, visible in history | suitable for large and sensitive data |
| for searches and filters | for 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?
| localStorage | sessionStorage | Cookies | |
|---|---|---|---|
| Lifetime | until cleared | until tab closes | set by expiry |
| Size | ~5 MB | ~5 MB | ~4 KB |
| Sent to server | no | no | with every request |
| Use | preferences, cache | per-tab state | sessions, 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).