title: function is hoisted. fun1 called fun2. in what order are they declare?
body: <p>I want to know the order in which the function is declared in javascript.</p>
  
  <pre><code>function ex1() {
    document.write("ex1")
  }
  
  function ex2() {
    ex1();
  }
  ex2();
  //result is ex1.
  </code></pre>
  
  <pre><code>function ex2() {
    ex1();
  }
  
  function ex1() {
    document.write("ex1")
  }
  ex2();
  //result is ex1.
  </code></pre>
  
  <p>I expect an error to occur if change the order.
  I know js use hoisting. But at the top, I thought it would be declared in order .
  How was the function called?</p>