paint-brush
#JavaScript Hoisting: Where Did My Function Go?by@astepanov256
504 reads
504 reads

#JavaScript Hoisting: Where Did My Function Go?

by Alex Stepanov2mDecember 5th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

A curious case of a function definition that made me pause and squint. The code looked somewhat like this: Quick quiz: can you spot a problem here? The anonymous function is never called, thus the error message is never displayed. JavaScript throws a curve ball at the uninitiated by following a somewhat unique set of rules called "hoisting" The rules mean that the function declarations are automatically moved to the top of the enclosing scope. It does not really matter where the function is defined - before the call or after, as long as the call happens within the same scope as the function declaration.

Company Mentioned

Mention Thumbnail
featured image - #JavaScript Hoisting: Where Did My Function Go?
Alex Stepanov HackerNoon profile picture
Alex Stepanov

Alex Stepanov

@astepanov256

Software Engineer, Writer, Recovering Perfectionist

Learn More
LEARN MORE ABOUT @ASTEPANOV256'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Alex Stepanov HackerNoon profile picture
Alex Stepanov@astepanov256
Software Engineer, Writer, Recovering Perfectionist

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Also published here