title: Declaring function inside class component vs inside functional component
body: <p>I am playing with function syntax inside and outside class components. Can anyone explain to me why the print function works when written like this</p>
  
  <pre><code>const UploadButton = (props)=&gt; {
  
      const fileName = 'myfile';
  
  
      props.getFileName(fileName)
  
      function print(){console.log('onClick worked')}
  
      return(
  
          &lt;div&gt;
              &lt;input onClick= {print()} type="file" id = {fileName}/&gt;
          &lt;/div&gt;
      )
  }
  
  </code></pre>
  
  <p>but when i write it like i would when declaring it inside a class component:</p>
  
  <p><code>print(){console.log('onClick worked')}</code></p>
  
  <p>i get this error</p>
  
  <pre><code> Line 10:  Parsing error: Unexpected token, expected ";"
  
     8 |  props.getFileName(fileName)
     9 | 
  &gt; 10 |   print(){console.log('onClick worked')}
       |          ^
  </code></pre>