SShortSingh.
Back to feed

structuredClone() vs JSON.stringify(): The Right Tool for Deep Copying in JS

0
·7 views

JavaScript developers have long used JSON.parse(JSON.stringify()) as a quick workaround for deep-copying objects, but the technique has notable limitations. It fails to correctly handle data types like Date, Map, Set, and undefined, and throws a TypeError when encountering circular references. The structuredClone() API, built specifically for cloning structured data, handles all these cases more reliably and even preserves circular reference relationships in the cloned output. However, structuredClone() is not without constraints — it cannot clone functions, DOM nodes, or prototype chains. Developers are advised to use structuredClone() for deep copying data and reserve JSON.stringify() for its intended purpose of serialization.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Why AI Automation Workflows That Shine in Demos Often Fail in Production

AI automation pipelines that appear seamless during demos frequently break down once real-world conditions are introduced, such as waiting for human approvals, retrying failed API calls, or pausing for external events. The core problem is that most demo workflows are built as simple request-response sequences, but any workflow that must outlive a single HTTP request requires deliberate distributed systems design. Platform constraints compound the issue — AWS Lambda's 15-minute execution limit and Cloudflare Workers' CPU-time caps make long-running agent tasks unsuitable for basic webhook handlers. Tools like self-hosted n8n shift into a split architecture in queue mode, introducing Redis brokers, worker processes, and shared state management that far exceed typical low-code expectations. Frameworks such as Inngest address this more cleanly by not tying concurrency to waiting or sleeping steps, making them better suited for always-on AI agents that pause mid-workflow.

0
ProgrammingDEV Community ·

How to Build a Secure Authentication System: Key Concepts and Best Practices

A secure authentication system is a critical component of modern software applications, required across websites, banking platforms, mobile apps, and business tools. Beyond a basic login form, a robust system must handle password protection, input validation, session management, and account recovery. Core concepts include distinguishing authentication — verifying who a user is — from authorization, which governs what resources a user can access. Such a system can be built using a range of technologies including Python, JavaScript, Node.js, and databases like MySQL or MongoDB, while the underlying security principles remain consistent. Key implementation areas covered include password hashing, multi-factor authentication, role-based access control, rate limiting, and security logging.

0
ProgrammingDEV Community ·

Dev Team Builds MCP Server to Let AI Agents Sync Code Directly with Allure TestOps

A developer built a custom MCP server for Allure TestOps after noticing that coding agents accelerated development but left manual bottlenecks in the testing workflow. Previously, developers relied on a human to manually transfer information between the codebase, the test management system, and other tools like MockServer. With the MCP integration, an AI agent can read an existing Android UI test, parse its steps, and automatically create or update the corresponding test case in Allure TestOps without human intervention. The same agent can also read a TestOps test case and generate the required mocks via a separate MockServer MCP, linking multiple systems in a single automated flow. The team now uses the agent to audit test coverage — identifying which test cases are automated, which are missing documentation, and where code changes have made existing descriptions stale.

0
ProgrammingDEV Community ·

Developers Build AI Customer Support Agent With Persistent Memory Across Sessions

A team of developers has created a Customer Support Memory Agent as a hackathon project, designed to solve the common problem of customers having to repeatedly re-explain their issues to support systems. The agent uses a memory tool called Hindsight to retain and recall key details from past customer interactions, such as previous tickets, refunds, and billing disputes. When a returning customer sends a new message, the system retrieves relevant stored context and passes it to a Groq large language model, which then generates a personalized, context-aware response. The architecture is built on a Python and Flask backend with a web UI frontend, and it maintains separate memory profiles for individual customers. The memory system can also organize past interactions into a graph structure, visualizing relationships between events in a customer's history.