class Example extends React.Component {render() {const { className, children } = this.props;return (<div className={className}>{children}</div>);}}ReactDOM.render([<Example className="first"><span>Child in first</span></Example>,<Example className="second" children={<span>Child in second</span>} />],document.getElementById("root"));
const obj = {foo: {a: 1,b: 2,c: 3}};console.log("original", obj.foo);// Creates a NEW object and assigns it to `obj.foo`obj.foo = {...obj.foo, a: "updated"};console.log("updated", obj.foo);
const arr1 = [1, 2, 3, 4, 5]const arr2 = arr1 // [1, 2, 3, 4, 5]/*This is an example of a shallow copy.Where the value of arr1 is copied to arr2But now if you apply any method toarr2 will affect the arr1 also.*/
/*This is an example of a deep copy.Here the values of arr1 get copied but theyboth are disconnected. Meaning if youapply any method to arr3 it will notaffect the arr1.*/const arr3 = [...arr1] // [1, 2, 3, 4, 5]