title: What happens in Javascript in this particular case (Call by sharing)?
body: <p>Javascript uses Call by Sharing, but I  have question related to something in React. </p>
  
  <p>What happens when you set a state (setState Hook or Class State) inside a function? e.g: </p>
  
  <pre><code>const [myState, setMyState] = useState(null);
  
  const foo = () =&gt; {
     const bar = {'prop': 1};
     setMyState(bar);
  }
  
  foo();
  </code></pre>
  
  <p>How javascript keeps track of the state value that was set inside the function, cause as far as I understand, <code>bar</code> dies after executing <code>foo</code>.</p>
  
  <p>Does setState copy the passed value or am I missing something?</p>