Here are some common frontend interview questions along with brief answers:
1. What is the DOM (Document Object Model)?
- Answer: The DOM is a programming interface for web documents. It represents the structure of a web page and allows scripts to dynamically access and update the content, structure, and style of a webpage.
2. Explain the difference between null and undefined in JavaScript.
- Answer: null represents the intentional absence of any object value, while undefined represents a variable that has been declared but has not been assigned a value.
3. What are closures in JavaScript?
- Answer: Closures are functions that remember the scope in which they were created, even after that scope has exited. They have access to variables from their containing function's scope.
4. Describe the differences between CSS Grid and Flexbox.
- Answer: CSS Grid is a two-dimensional layout system, while Flexbox is one-dimensional. Grid is used for overall layout structure, while Flexbox is ideal for distributing space and aligning items within a container along a single axis.
5. What is responsive web design, and how do you achieve it?
- Answer: Responsive web design is an approach to design and coding that makes web pages render well on various devices and screen sizes. Achieve it through media queries, flexible grids, and fluid images.
6. Explain the "box model" in CSS.
- Answer: The box model describes how elements on a web page are rendered. It consists of content, padding, border, and margin, and these properties determine the element's total size.
7. How does the event delegation work in JavaScript?
- Answer: Event delegation is a technique where you attach a single event listener to a common ancestor of multiple elements instead of attaching listeners to each element individually. Events that bubble up from child elements can be handled by the ancestor.
8. What is the purpose of the localStorage and sessionStorage objects in JavaScript?
- Answer: Both localStorage and sessionStorage allow you to store key-value pairs in a web browser. The key difference is that data stored in localStorage persists even after the browser is closed, whereas data in sessionStorage is cleared when the session ends (e.g., when the browser is closed).
9. Explain the same-origin policy in the context of web security.
- Answer: The same-origin policy is a security measure that restricts web pages from making requests to a different domain (protocol, port, or host) than the one that served the web page. It helps prevent cross-site request forgery (CSRF) and other security vulnerabilities.
10. What are the benefits of using a CSS preprocessor like Sass or Less?
- Answer: CSS preprocessors provide benefits such as variables, nesting, functions, and mixins, which enhance code reusability, maintainability, and organization. They allow you to write cleaner and more efficient CSS.
Web Development Best Resources:
https://topmate.io/coding/930165ENJOY LEARNING 👍👍