title: javascript: variable defined vs function undefined
body: <p>I have two arrays:</p>
  
  <pre><code>array1 = ["one", "two"];
  array2 = ["two", "four"]; 
  </code></pre>
  
  <p>If I write:</p>
  
  <pre><code>var inetersection = array1.filter(function(n){
      return array2.indexOf(n) != -1 
   });
  </code></pre>
  
  <p>I get the right answer: "two".</p>
  
  <p>But if I write a function:</p>
  
  <pre><code>function intersection (array1, array2){
     array1.filter(function(n){
     return array2.indexOf(n) != -1
     });
  }
  </code></pre>
  
  <p>then <code>console.log(intersection(array1, array2));</code>returns <code>undefined</code> </p>
  
  <p>what is wrong with the second syntax?</p>