Constant confusion: why I still use JavaScript function statements
Bill Sourour
2.3K37

Hoisting Function Statements is so crucial!

With hoisting, the top of the file contains the “what”.

// create a user

check_if_username_is_available()
.then( check_if_email_is_registered )
.then( store_details_in_db )
.then( send_email_verification );

“This is what happens, this happens after and this is what happens in the end”

At the bottom of the file is the “how”.

function check_if_username_is_available(){

// connect to redis
// check in-memory cache of usernames
// return result of check
}

On jumping into the file, I get the 50,000 foot view of what’s happening and I know where to go when I want to drill into how a certain thing is being done.

Save a JS dev: Hoist your Functions

Like what you read? Give MobiuS a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.