𝕊𝕚𝕤𝕪𝕡𝕙𝕖𝕒𝕟

A little insane, but in a good way.

Why this name?

  • 34 Posts
  • 17 Comments
Joined 1 year ago
cake
Cake day: June 14th, 2023

help-circle
































  • Not a stupid question at all.

    Other than the syntax, there is a very important functional difference between the two: function definitions are hoisted, consts are not. What this means in practice is that you can use a function you define later in the file if it’s defined using the function f() { ... } syntax, but const f = () => { ... } functions can only be used after their definitions.

    function f() { g() } // OK
    function g() {}
    
    const f = () => { g() } // Error
    const g = () => {}
    

    Personally, I like breaking up React components into smaller helper subcomponents and use them in a main component. I only export the main component, the helpers are private to the module. For better readability, I like the main component to be at the top of the file and then put the helpers in decreasing order of complexity. This style is only possible with classic function definitions, using consts forces you to use bottom-up instead of top-down order.