title: Weird effect when calling an hoisting function in javascript
body: <p>I am very newbie in JavaScript. I learned Hoisting behavior in JS and i tested it by myself with a simple program example.</p>
  <p>My program generate an Array which contains random numbers then call <code>unique()</code> who deletes all duplicates elements inside the Array :</p>
  <pre><code>const NUMBERS = [34, 25, 45, 11, 36, 98, 58, 97, 56]
  const ARRAY_LENGTH = 4;
    
  function getRandomNumberList () {
    let res = []
    for (i = 0; i &lt; ARRAY_LENGTH; i++) {
      res.push(NUMBERS[Math.floor(Math.random() * ARRAY_LENGTH)])
    }
    return res
  }
  
  
  // Generate array with random numbers 
  let randomArray = getRandomNumberList() 
  
  // When we compute this, First call doesn't Work
  // the console.log return [ 34, 45, 34, 34 ]
  console.log(randomArray)
  
  // First call with Hoisting
  // Because of console log, return [ 34, 45, 25 ] instead of [ 34, 45 ]
  unique(randomArray)    
  
  // This function remove duplicates entries if exist.  
  function unique (arr) {
     let uniqueArray = [...new Set(arr)]  
     return uniqueArray 
  };
  
  // Second call without hoisting. This seems to work all the time
  // return [ 34, 45 ]
  unique(randomArray)
  </code></pre>
  <p>However, I was confronted to a weird behavior.</p>
  <p>The First call doesn't work when I call <code>console.log</code> <strong>above</strong> the first call. However if I remove the console.log(), it's seems to work.</p>
  <p>Can anyone pls explain me why this behavior occurred ?</p>
  <p><strong>Note that</strong> I used <strong>RunJS</strong> scratchpad to run my program.</p>