Dev communicates
2 subscribers
7 photos
3 files
20 links
Download Telegram
«کتاب تفکر سیستمی نوشتهٔ جمشید قراچه داغی» از جمله کتاب‌های مطرح این حوزه در سطح جهان است و بسیاری از دانشگاه‌ها و مراکز عالی به عنوان منبع و مرجع آموزش نگرش سیستمی استفاده می‌کنند.
امروزه اگر قرار باشد از چهار یا پنج فرد برتر در حوزهٔ تفکر سیستمی در سطح جهان نام ببریم، نام جشمید قراچه داغی هم در این فهرست وجود خواهد داشت و در کنار کسانی مانند پیتر سنگه و راسل اکاف قرار می‌گیرد.
Forwarded from Dev communicates (Pourya Daneshvar)
🎯 I was asked this in a recent interview:
"How do you deep copy an object in JavaScript?"

It might sound simple, but it’s one of those questions that reveal how well you really understand the language.

Shallow vs Deep Copy, what’s the difference?

In JavaScript, shallow copy and deep copy refer to how data structures (especially objects and arrays) are duplicated. The key difference lies in how nested objects or arrays are handled.

🔹 Shallow Copy
A shallow copy copies only the first level of the object or array. Nested objects or arrays are still referenced, not duplicated.

🔧 Tools for shallow copy:
- Object.assign({}, obj)
- Spread syntax: { ...obj }, [ ...array ]
- Array.prototype.slice()


🔹 Deep Copy
A deep copy duplicates everything, including nested objects. Changes in the copy won’t affect the original.

🔧 Tools for deep copy:
- structuredClone(obj) ( modern, built-in)
- JSON.parse(JSON.stringify(obj)) (⚠️ may fail with functions, undefined, circular refs)
- Libraries: lodash.cloneDeep(obj)

Use the right one depending on your data structure and avoid hidden bugs in your app!

#javascript
interface User {
name: string;
age: number;
email: string;
}
const updateUser =
(user: Partial<User>) => ({
... user, updatedAt: new Date(),
}):
updateUser ({ name: "John" }) ;
interface User {
name: string;
age: number;
email: string;
}
const updateUser =
(user: ?????) => ({
... user, updatedAt: new Date(),
}):
updateUser ({ name: "John" }) ;
#macos installer

softwareupdate --list-full-installers
softwareupdate --fetch-full-installer --full-installer-version 26.x