$ ls index/

engineering / frontend / javascript

JavaScript Function Syntax

$cat engineering/frontend/javascript/js-function-syntax.md

The Four Forms

// 1. Function declaration — hoisted, callable before definition
export default function MyComponent() { ... }

// 2. Named export declaration — hoisted, multiple exports per file
export function helperFn() { ... }

// 3. Const arrow / expression — NOT hoisted, must be defined before use
export const helperFn = () => { ... }

// 4. Local declaration — no export, file-scoped only
function internalHelper() { ... }

Key Differences

function declarationconst arrow
HoistedYesNo (temporal dead zone)
this bindingDynamicLexical (inherits from outer scope)
Can be a methodYesYes
arguments objectYesNo

Hoisting matters when you call a function above its definition in the file. const will throw a ReferenceError; function declarations work fine.

In React / Next.js

Both styles are common for components — it's a style choice, not a correctness one:

// Declaration style — what Next.js docs use for pages/layouts
export default function Page() {
  return <main />
}

// Expression style — common in component libraries and some style guides
const Page = () => <main />
export default Page

Consistent rule of thumb:

  • Pages and layouts → export default function (matches Next.js conventions)
  • Utility functions in a module → named exports, either form is fine
  • Single-export utility file → export default function
  • Multiple exports in one file → named export function or export const

Let's build something impactful together.

ertughaskan@gmail.com Find me online
Availability
WorkAvailable
RelocationOpen
FreelanceClosed
© 2026 Ertugrul Alex Haskan /cookiesVancouver, BC 🇨🇦

This site uses one optional Google Analytics cookie to see which pages get read. Nothing is set until you choose — cookie details.