This tricky spread operator #javascript question was asked in #deloitte #frontend interview #coding

preview_player
Показать описание
This tricky spread operator #javascript question was asked in #deloitte #frontend interview #coding #programming
Рекомендации по теме
Комментарии
Автор

Shallow will only work for the current object, so in your case it will work but if there is nested referenced types in the object they'll still be modifiable via the shallow copy, so be carefull.

Basically it will only work if the object you shallow copied only has 1 layer, for a deep copy you'll need to clone using "const clone = structuredClone(object);" (or whatever trick you want to use) that way all the references of the main object and the nested types in it have their own references.

honkhonkv
Автор

The spread operator only copies top level primary values without reference. If you have nested objects then those will still be by reference. Best is to use structuredClone

the_BetaDev
Автор

= is not equal to or equality operator. Its an assignment operator.

basic--advance
Автор

You explained wrong I think bcoz I searched on chatgpt and it says spread is shallow copy and even logic in first one doesn't seem to be for the result you got . So kindly check it

Harshil-kw
Автор

wtf is Deloitte doing? Who is asking these intern level questions

foobarfuzzbuzz
welcome to shbcf.ru