JavaScript functions Flashcards

1
Q

What is function in JavaScript?

A

a group of reusable code that you can use anywhere in the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give at least one benefit of JavaScript function.

A

It reduces repetition of code within a program. It becomes easier to eliminate the errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do you need to call a function?

A

Because a defined function does not execute automatically. A function only specifies what to do when we execute the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a parameter in a function?

A

used inside a parenthesis in a function declaration. It takes the value of what the function arguments contain and work with them entirely of the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The lifetime of parameters is only inside the function. True or false?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

We can pass up to 25 parameters, separated by commas. True or false?

A

False. We can pass up to 255 parameters, separated by commas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference of a parameter and an argument?

A

Arguments are the actual values that we pass to a function at the time of function call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The names of a parameter and an argument cannot be the same. True or false?

A

False. It can be the same or different, depends on your preference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Function return. A function can return a value back to the script that called the function by using the return statement. True or false?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is local scope?

A

A local scope variable is a variable that can only be used inside the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Global scope can only be used inside the function. True or false?

A

False. It can be used in a function and outside the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A variable that has not been declared will automatically become local scope. True or false?

A

False. It automatically becomes global scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly