DEV Community

CristinaV
CristinaV

Posted on

Beginner here, have mercy!

Hi All,

My brain is stuck and I need help.
I'm just going through the JS Fundamentals training and for the life of me, I cannot seem to fully understand when to use a variable keyword (let, const) or the "function" keyword.

I understand what each does, I've gone through the theory 4 times until now but... something's missing.

Can someone help me, please?

I hope I made this clear enough...

Top comments (1)

Collapse
 
vonheikemen profile image
Heiker

Are you familiar with the term "hoisting"? I believe that's one thing that would make you choose the function keyword over let or const.

So, when I'm creating a example snippet in codepen I will often put helper functions at the bottom of the script so the reader can have the important bits at the beginning of the script.

const dataset = get_data();
const names = dataset.map((thingy) => thingy.name);

// Helper functions that I think 
// are not relevant to the reader.

function get_data() {
  // cool code...
  return things;
}
Enter fullscreen mode Exit fullscreen mode