How do you order your functions?

Aral Roca - Jul 26 '20 - - Dev Community

Many linters complain that functionA cannot be declared on bottom of functionB when this is the case:

function first(){
  second()
}

function second(){
  // Whatever
}

This rule will warn when it encounters a reference to an identifier that has not yet been declared.

Rule of Eslint: https://eslint.org/docs/rules/no-use-before-define

So, we will change it to:

function second(){
  // Whatever
}

function first(){
  second()
}

And I've been following this rule in my projects. But I always wonder, if it really matters that much... Since JavaScript seems to handle function declarations well even if they're not in the right order.

And the truth is, we're used to reading from up to down. And for me to do this makes it much more understandable:

function first(){
  second()
  third()
}

function second(){
  fourth()
}

function third(){
  // Whatever
}

function fourth(){
  // Whatever
}

How do you sort the functions? I'd like to hear about this.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player