r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

1

u/jun-thong May 29 '19

The following will break, telling myFunc is not defined.
myFunc();
const myFunc = function(){ ... };

The following one won't trigger error.

myFunc();
function myFunc() { ...}

The first one is called "function expression", the second one is called "function declaration". Understanding the difference teach a lot about how js is interpretedby the runtime.