Short answer: The <canvas> element is used to draw graphics, animations, charts, or games using JavaScript. Example: <canvas id="myCanvas" width="200" height="100"></canvas> <script> const canvas = document.getElementById("myCanvas"); ctx.fillStyle = "blue"; ctx.fillRect(10, 10, 180, 80); </script> Follow me on LinkedIn: Key Takeaway: <canvas> gives you a pixel-based drawing area inside HTML — perfect for dynamic graphics.
Example code
const ctx = canvas.getContext("2d");
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.