- There is a code between the 1st log and the 2nd log. I assign the
validate
variable to thes
variable using thelet
definition type.
console.log(validate); // 1. log
let s = validate;
if (s.location != null)
delete s['location'];
console.log(validate.location); // 2. log
In this case, the screen output looks like this:
{ // 1
min_price: 2,
max_price: 5,
location: { latitude: 234.2244555, longitude: 245.33333 }
}
undefined // 2
Isn't it very strange? Because after I do let s = validate;
I do delete s['location];
but after this operation when I do console.log(validate.location);
I get undefined
.
- So I wrote the following instead of
let s = validate;
on the code and the result was fine:
let s = {
...validate
};
In this case, when we take the screen output again, the output is fixed as follows:
{ // 1
min_price: 2,
max_price: 5,
location: { latitude: 234.2244555, longitude: 245.33333 }
}
{ location: { latitude: 234.2244555, longitude: 245.33333 } } // 2
Now my question is, is the difference between let s = validate;
and let s = { ...validate };
because of the let
definition type? Because I couldn't find a logical explanation for this conflict.