click below
click below
Normal Size Small Size show me how
JavaScript topics
JavaScript topics review
| Question | Answer |
|---|---|
| What is a closure in JavaScript? | A closure is when a function keeps access to variables from the place it was created, even after that outer function has finished running. It’s like saving the surrounding context for later use. |
| What problem do closures help solve? | They let you keep private data and create functions that “remember” values without exposing them directly, which makes your code cleaner and safer. |
| How does the keyword this work in JavaScript? | “this” refers to the object that is currently running the code. Its value changes based on how a function is called, not where it was written. |
| What is the value of this inside an arrow function? | Arrow functions don’t create their own “this.” They just use the “this” from the place they were written, making them simpler for callbacks. |
| What is the event loop? | The event loop manages the order in which JavaScript runs tasks, letting long operations wait while the page stays responsive instead of freezing. |
| What does async/await do? | It lets you write code that waits for something to finish—like a network request—without freezing the page, making asynchronous code look more readable. |
| What is a Promise? | A Promise is a placeholder for a value that you don’t have yet, like waiting for food you ordered. It can finish successfully or fail. |
| What triggers a React component re-render? | A re-render happens when its state or props change, causing React to update what appears on the screen. |
| What does useState do? | useState lets a component store a value that can change over time. When the value changes, React updates the UI to match. |
| What does useEffect do? | useEffect lets you run code after the component renders—like fetching data or listening to events. You control when it runs with the dependency array. |
| What does passing an empty array to useEffect mean? | It means “run this code only once when the component first shows up,” similar to a componentDidMount behavior. |
| What is the React rendering lifecycle in simple terms? | React shows the component, reacts to changes in data, updates the screen, and cleans things up when the component disappears. |
| How does CSS specificity work? | Specificity decides which CSS rule wins when multiple rules apply. IDs beat classes, and classes beat element tags. |
| What is a CSS flex container? | A flex container helps its child elements line up easily in rows or columns, adjusting space automatically without manual positioning. |
| What is the difference between padding and margin? | Padding is space inside an element around its content; margin is space outside an element separating it from others. |
| What is SQL used for? | SQL is a language for interacting with databases—asking for data, adding new info, updating it, or organizing it. |
| What does SELECT do in SQL? | SELECT asks the database to return specific data, like “show me all users older than 25.” |
| What does WHERE do in SQL? | WHERE filters results so you only get rows that match certain conditions, like “only active accounts.” |
| What does JOIN do in SQL? | JOIN connects related data from multiple tables so you can see combined information in one result. |
| What is a primary key? | A primary key is a unique identifier for each row in a database table so you can reliably search for or link that row. |
| What is the DOM? | The DOM is a live tree that represents everything on a web page, letting JavaScript read or change elements on the screen. |
| What is event bubbling? | When an event happens on an element, it travels upward through its parent elements, giving each a chance to react. |
| What is event delegation? | Instead of putting many event listeners on many items, you put one on a parent and handle events as they bubble up. |
| Difference between var, let, and const? | var is old and loose, let is block-scoped and flexible, const is block-scoped and can’t be reassigned. |
| What is hoisting? | JavaScript moves variable and function declarations to the top of their scope before running the code, affecting how they behave. |
| What is a pure function? | A function that always returns the same output for the same input and doesn’t change anything outside itself. |
| What is immutability? | It means you don’t change existing data directly—you make new versions, which helps prevent bugs. |
| What is debounce? | Debounce waits for a pause in rapid actions before running a function, like waiting for typing to stop before searching. |
| What is throttle? | Throttle limits how often a function can run, helping performance when something triggers too many events. |
| What is the difference between synchronous and asynchronous code? | Sync code waits step-by-step; async code allows other work to continue while waiting for something to finish. |
| What is localStorage? | A browser storage area where you can save small amounts of data that stay even after the page reloads. |
| What is sessionStorage? | Like localStorage but the data disappears when the browser tab closes. |
| What is CORS? | CORS is a browser security rule that decides whether a site can request data from another site. |
| What is responsive design? | A way of designing sites so they adjust nicely on phones, tablets, and desktops without breaking. |
| What are media queries? | CSS rules that apply only at certain screen sizes or conditions, helping make layouts responsive. |
| CORS Stands for | Cross-Origin Resource Sharing |
| What is CSS Grid? | A layout system that gives you full control over rows and columns for complex page designs. |
| Difference between display: none and visibility: hidden? | display: none removes the element from layout; visibility: hidden keeps its space but hides it. |
| What is z-index? | A CSS property that controls what sits “on top” when elements overlap. |
| What causes layout thrashing? | Repeated layout calculations caused by reading and writing layout values too often, slowing the page. |
| What is a virtual DOM? | A lightweight copy of the page structure React uses to figure out the smallest changes needed before updating the real page. |
| What does DOM stand for | Document Object Model |
| Why does React need keys in lists? | Keys help React track which items changed, so it can update the UI efficiently instead of redoing everything. |
| What is lifting state up in React? | Moving shared data to a parent component so multiple children can use it without confusion. |
| What is prop drilling? | Passing data through many layers of components just so a child component can use it. |
| What is the Context API? | A way to share data across many components without manually passing props through every layer. |
| What is a controlled component in React? | An input whose value is fully managed by React state instead of the browser’s default behavior. |
| What is a build step (like Webpack or Vite)? | Tools that bundle, optimize, and prepare your code so it loads faster in the browser. |
| What is tree shaking? | Removing unused code during the build to reduce bundle size. |
| What is lazy loading? | Loading parts of the app only when needed instead of all at once, improving startup speed. |
| What is hydration in React? | The process where React attaches interactivity to HTML that was already rendered on the server. |
| What is SSR? | Server-Side Rendering sends ready-made HTML from the server, improving speed and SEO before the page becomes interactive. |
| What is a 3rd-party script performance issue? | Extra scripts from ads, analytics, or widgets can slow down page loading by blocking rendering. |
| What is Redux used for? | Redux stores shared data in one central place so different parts of your app stay in sync without passing props everywhere. |
| What is an action in Redux? | An action is a plain object describing what happened—like “user logged in”—so the store knows how to update. |
| What is a reducer? | A reducer is a function that takes the current state and an action, then returns a new state without modifying the old one. |
| What is the Redux store? | The store holds the entire app’s state in one place and lets components read it or ask for updates. |
| What is dispatch? | Dispatch sends an action to the store, telling Redux to run the reducers and update the state based on that action. |