Viva Questions and Answers - HTML, CSS, JavaScript, React
HTML
CSS
Q: Difference: inline, internal, external CSS?
A: Inline in tag, internal in <style>, external in .css file.
Q: What is the box model?
A: Content, padding, border, and margin.
Q: Pseudo-classes and pseudo-elements?
A: :hover, :nth-child(); ::before, ::after.
Q: What is specificity?
A: Priority of CSS rules based on selector weight.
Q: Difference: em, rem, %, px?
A: em: parent font; rem: root font; %: relative; px: fixed.
Q: Position values in CSS?
A: relative, absolute, fixed, sticky.
Q: visibility: hidden vs display: none?
A: Hidden: invisible but space taken; None: no space.
Q: How do media queries work?
A: They apply styles based on screen/device properties.
Q: Flexbox vs Grid?
A: Flexbox is 1D; Grid is 2D layout system.
Q: What is z-index?
A: Defines stack order of elements.
JavaScript
Q: Data types in JavaScript?
A: Primitive: string, number, etc.; Non-primitive: objects.
Q: What is hoisting?
A: Variable/functions declarations move to top.
Q: var vs let vs const?
A: var is function-scoped; let & const are block-scoped.
Q: What is closure?
A: Function that remembers its lexical scope.
Q: What is event delegation?
A: Parent handles events of child via bubbling.
Q: Promises and async/await?
A: Handle async code; async/await simplifies promises.
Q: == vs ===?
A: == checks value; === checks value and type.
Q: What is DOM?
A: Document Object Model - structure of web page.
Q: Synchronous vs Asynchronous?
A: Sync: sequential; Async: non-blocking.
Q: What is 'this' in JS?
A: Context of executing function.
React
Q: What is React?
A: A JS library for building user interfaces.
Q: What are components?
A: Reusable pieces of UI.
Q: Functional vs Class components?
A: Functional: simpler, use hooks; Class: use lifecycle methods.
Q: What is JSX?
A: JavaScript XML - lets us write HTML in JS.
Q: What is virtual DOM?
A: Lightweight copy of real DOM for faster updates.
Q: What are props and state?
A: Props: external inputs; State: internal data.
Q: What is useEffect?
A: Hook for side effects like API calls.
Q: What are hooks?
A: Functions like useState, useEffect for functional components.
Q: Controlled vs Uncontrolled components?
A: Controlled: via state; Uncontrolled: DOM handles data.
Q: What is Context API?
A: Passes data through tree without props.