Facebook Pixel

Should you use arrow functions or regular function declarations?

Use regular function declarations for top-level helpers you want to call from anywhere. Use arrow functions with const for most other cases, and always declare them before calling to avoid TDZ or TypeError issues.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Hoisting With Arrow Functions and Regular Functions

No, not as functions. Arrow functions are function expressions assigned to a variable. The variable is hoisted (undefined with var, TDZ with let/const), but the function body is only assigned at the declaration line.

With var, TypeError: x is not a function (because the variable is undefined). With let or const, ReferenceError because the variable is in the Temporal Dead Zone.

Yes. Regular function declarations are hoisted with their entire body during the memory allocation phase, so they can be called before their declaration line.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.