Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/9220762 to your computer and use it in GitHub Desktop.
Save rlemon/9220762 to your computer and use it in GitHub Desktop.

#poll

What do you prefer to read:

A:

function foo() { return 1; }

var foo = foo();

or

B:

var foo = foo();

function foo() { return 1; }

Please comment.

@SomeKittens
Copy link

Declare things before using them.

@monners
Copy link

monners commented Feb 26, 2014

Declare things before using them (2X).

@Qantas94Heavy
Copy link

Neither, it's a bad idea to use the same variable name for both a function and its result. If you're only using it once, use an IIFE instead.

@m59peacemaker
Copy link

B, but with a different var name. I agree with Qantas regarding that. I like to see the most summarized code (function call) and then investigate the function elsewhere if I need to. To me, "A" would be like reading through the jQuery library before calling .hide(). If I want to know what .hide() does, I'll look for it and read it. In that light, maybe that function could be in it's own library that is required in and then it doesn't have to be above or below :)

@rlemon
Copy link
Author

rlemon commented Feb 26, 2014

@Qantas94Heavy you are losing scope of the question i'm afraid.

@eternalruler
Copy link

A; the order of declarations let's me know that function foo(){...} is no longer accessible and var foo has overwritten it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment