Functions: Function parameters

A function can have no parameter, like we’ve seen previously:

function test() {
  //do something
}

Or it can have one or more parameters, which are declared inside the parentheses:

function test(color) {
  //do something
}

function test(color, age) {
  //do something
}

When we can pass a parameter, we invoke the function passing arguments:

function test(color, age) {
  //do something
}

test("green", 24)
test("black")

The difference between arguments and parameters is this: you define the parameters and that’s what you see inside the function. Arguments are passed by the program when you call the function.

They are basically the value assigned to the parameter.

Functions can have default values for the parameters that are not passed by the caller:

function test(color = 'red', age = 20) {
  console.log(color, age)
}

test("green", 24)
test("black")

Lessons in this unit:

0: Introduction
1: ▶︎ Function parameters
2: Returning values from a function
3: Arrow functions
4: Nesting functions
5: Immediately-invoked functions
6: Recursive functions
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!