JavaScript Best Practices: Functions

  • Function expressions:
  • Function declarations:
  • Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.
  • Note: ECMA-262 defines a block as a list of statements. A function declaration is not a statement. Read ECMA-262's note on this issue.
  • Never name a parameter arguments. This will take precedence over the arguments object that is given to every function scope.

--

--

--

Trusted Veteran | Compassionate. Aspiring. Resourceful.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Chapter 2 Manage Data Collections with Arrays

Early praise for Test-Driven React

Why is React is So Popular?

Separating the App into Components

images/9-grid-based-design/10-static-ui/customer-search-details.png

Implementing a Trie in JavaScript Part 2

Angular Development in the Dallas Area

JavaScript Tutorial — Lexical Environment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Austin Songer

Austin Songer

Trusted Veteran | Compassionate. Aspiring. Resourceful.

More from Medium

More About JavaScript, Version Controlling, NoSQL

Importance of Reading Other’s Code

My Journey Into The JavaScript Abyss

Asynchronous Code Execution in JavaScript