Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Passing Data into Functions | Mastering Functions
Introduction to JavaScript
course content

Kursinnhold

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
Passing Data into Functions

We can pass data into functions using parameters:

js

A parameter acts like a local variable inside the function. However, it takes up the value of the corresponding argument that is passed into the function at the function call.

12345678
function sum(a, b) { console.log(a + b); } sum(1, 2); // Output: 3 sum(5, 10); // Output: 15 sum(20, 30); // Output: 50 sum(33, 37); // Output: 70
copy
  • An argument is the actual value passed into a function when calling it:

    • Example: In sum(1, 2), the values 1 and 2 are arguments;

  • A parameter is a placeholder inside the function definition that receives the argument’s value:

    • Example: In function sum(a, b), a and b are parameters.

Note
Study More

A function in which other functions are called is known as a compound function. A compound function combines smaller functions to accomplish a larger task.

1. How many parameters does this function have?

2. What will be the output of this code?

3. Which of the following is true?

question mark

How many parameters does this function have?

Select the correct answer

question mark

What will be the output of this code?

Select the correct answer

question mark

Which of the following is true?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 5

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
Passing Data into Functions

We can pass data into functions using parameters:

js

A parameter acts like a local variable inside the function. However, it takes up the value of the corresponding argument that is passed into the function at the function call.

12345678
function sum(a, b) { console.log(a + b); } sum(1, 2); // Output: 3 sum(5, 10); // Output: 15 sum(20, 30); // Output: 50 sum(33, 37); // Output: 70
copy
  • An argument is the actual value passed into a function when calling it:

    • Example: In sum(1, 2), the values 1 and 2 are arguments;

  • A parameter is a placeholder inside the function definition that receives the argument’s value:

    • Example: In function sum(a, b), a and b are parameters.

Note
Study More

A function in which other functions are called is known as a compound function. A compound function combines smaller functions to accomplish a larger task.

1. How many parameters does this function have?

2. What will be the output of this code?

3. Which of the following is true?

question mark

How many parameters does this function have?

Select the correct answer

question mark

What will be the output of this code?

Select the correct answer

question mark

Which of the following is true?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 5
Vi beklager at noe gikk galt. Hva skjedde?
some-alt