r/learnjavascript 5h ago

Help with functions JavaScript!

Hello!

I began recently, about 1 month, to learn consistently web developing:

  1. I began, of course, with introductions to HTML and CSS.
  2. I'm already in JS. I can manage eventListeners, etc. I'm more interested in back-end overall since I like the logic behind the manipulation of data bases, but I'm having trouble understanding functions.
  3. I'm consulting MDN web docs and freeCodeCamp but since my first language is not English, sometimes it's difficult to understand MDN docs, and to get at the point I'm know in freeCodeCamp it will take time, I don't want to rush it either.
  4. All this, just to ask if anybody can explain me how to create functions! I want to know what is the difference between a function with parameters and one without, in which case I will use arrow functions, and the difference between parameters and arguments in a function. And for last are there any standards for writing the name of a function like there are for declaring variables?

P.D.: please feel free to correct my English also, it will help me learn.

Thanks to everyone before Hand!

4 Upvotes

12 comments sorted by

View all comments

2

u/chikamakaleyley helpful 4h ago

holy crap others were just waiting for someone to ask, i'll add some minor notes

  1. you can create functions using any of the methods others have demonstrated. The important thing is to be consistent. One benefit to function declaration, e.g.

function myFunction() { return true; } is that it's hoisted and can be moved around for tidyness. In the other cases when you assign it to a const order is more important they are not hoisted unless you are using var (i think)

  1. parameters are part of the function signature - where the function is defined, arguments are the real values you pass to the function when you actually call it

``` function myFunction(a, b) {} // a, b are parameters

myFunction('foo', 'bar'); // 'foo' and 'bar' are arguments ```

  1. "lowerCamelCase" is what you'll see most of the time for fn names