Blog Posts
Frontend development insights
Frontend development insights
JavaScript employs the Event Loop in the browser to process asynchronous operations. It consists of: Call Stack Web APIs and Callback Queue When an asynchronous operation is completed, it places its callback in a queue known as the 'callback queue'. The Event Loop continually monitors the call stack and the call back queue. When a callback is clear, the event loop picks a callback from the queue and pushes it onto the stack for execution. The call stack records function calls in a Last-In-First-Out (LIFO) manner. Function calls push onto the stack: every time a function is invoked a stack frame is created and pushed onto the call stack Function returns pop the stack: when a function execution completes, its stack frame is popped from the stack. Thus, at any given point, only one stack frame (function) is actively executing, adhering to the principle of single-thread execution.
Approaches to fetching data API layer APIs are an intermediary layer btw your application code and database. Cases when u might use an API: a third party service that provides an API when fetching data from the client, u want to have an API layer that runs on the server to avoid exposing db secrets to the client In Next.js u create API endpoints using Route Handlers Database queries In a fullstack application, u also need to write logic to interact with ur database. In relational databases like Postgres, u can do with SQL or with an ORM. Cases when u write database queries: when creating ur API endpoints, u need to write logic to interact with the db when using React Server components (fetching data on the server) u can skip the API layer, and query ur database directly without risking to expose db secrets to the client. Note: when fetching data on the client, you should not query your database directly, as this would expose your database secrets.
Debouncing and throttling improve application performance by setting limits on how often a function is executed. These techniques are essential for managing "noisy" events—actions that trigger rapidly, such as scrolling or typing—to avoid excessive code execution or unnecessary network requests. Key Differences Debounce: Waits until activity stops for a specific duration before running the function. If a new event occurs during the wait time, the timer resets. Throttle: Ensures a function runs at most once every specified time interval, regardless of how many times the event is triggered. Debounce The Goal: Delay execution until the user has finished (or paused) an action. Use Cases Search Bars: Prevent a data-fetch request on every single keystroke. Form Validation: Wait until a user finishes typing an email address before showing an error message.
Check what's recreating it: Run this to see if Internet Sharing is active: bash sudo defaults read /Library/Preferences/SystemConfiguration/com.apple.nat If you see SharingDevices with entries, Internet Sharing has been configured. Disable it in System Settings → General → Sharing → Internet Sharing and make sure it's off. If you use Parallels or VMware, check that your VMs aren't set to Bridged networking mode — that's what creates the bridge at boot.