How do you copy by value a composite data type? in JavaScript

Primitive Data types
undefined vs null. Console output will be printed
call by value example
This is because no new memory is allocated arr1 and arr2 points to same memory

1. Using Spread

copy by value using spread operator

2. Using Object.assign()

copy by value using object.assign() method

3. Using JSON.parse() and JSON.stringify()

copy by value using stringify() and parse() method

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store