Javascript Functions and Parameters

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/16

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

17 Terms

1

Parameters

Inputs to a function (located inside parenthesis)

2

Example of a parameter

function doubleNumber(x){ ; The parameter here is x.

3

Scope

The part of the program where the variable exists

4

Local Variable

A variable that can only be used within the functions that define them.

5

Global Variable

A variable that can be used throughout a program in every scope.

6

Example of Local Variables

function myFunction(x){

let doubleX=x*2;

return doubleX;

}

The local variable would be doubleX and x because they are defined within the function

7

Why do we write functions?

They make our code easier to understand by giving a readable name to a group of instructions, they help us avoid writing repeated code, and make our code reusable.

8

What is the parameter of the function quardrupleNumber?

function quadrupleNumber(x){

var quadX=4*x;

println(quadX);

}

x

9

What is the output of the following code?

function start(){

var x=5;

quadruplesNumber(x);

}

function quadrupleNumber(x){

var quadX=4*x;

println(quadX);

}

20

10

What are the parameters of the printNumbers function?

function printNumbers(first, second, third){

println(first);

println(second);

println(third);

}

first, second, third

11

What is printed by the following code?

function printNumbers(first, second, third){

println(first); println(second); println(third); } function start(){

var middle = 5; printNumbers(4, middle, 6);

}

4

5

6

12

If we want to draw a circle using our helpful drawCircle function at position (300, 400) with a radius of 40 and color blue, which is the correct function call?As a reminder, here's the function header for drawCircle:

function drawCircle(radius, color, x, y)

drawCircle(40, Color.blue, 300, 400);

13

Do functions need to have parameters?

No

14

Which statements allows us to return values from functions?

return

15

What is printed when the following code is run?

function doubleNumber(x){

return 2*x;

} f

unction start(){

var y = 4;

var doubledY = doubleNumber(y);

var result = doubleNumber(doubledY);

print(result);

}

16

16

How many parameters go into the function sum?

function sum(first, second){

var result = first + second;

return result;

}

2

17

How many return values come out of the function sum?

function sum(first, second){

var result = first + second; return result;

}

1