Mid
From PDF
JavaScript
JavaScript
Explain the srcset and sizes attributes for <img>.
Short answer: They help browsers pick the best image for the user’s device and screen size. Follow me on LinkedIn:
Example code
<img src="small.jpg" srcset="medium.jpg 768w, large.jpg 1200w" sizes="(max-width: 768px) 100vw, 50vw" alt="Landscape"> srcset defines available image files and their widths. sizes tells the browser how much space the image will take on different screens. Key Takeaway: srcset + sizes = responsive images that load efficiently across devices.
Real-world example (ShopNest)
ShopNest’s browser cart uses modern JavaScript: fetch APIs with async/await, modules, and clear error handling.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png