0
0
Javascriptprogramming~5 mins

Function parameters in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are function parameters in JavaScript?
Function parameters are names listed in a function definition. They act like placeholders for values that the function will receive when called.
Click to reveal answer
beginner
How do you define a function with two parameters named a and b?
You write: <br><pre>function example(a, b) {<br>  // code here<br>}</pre>
Click to reveal answer
intermediate
What happens if you call a function with fewer arguments than parameters?
The missing parameters get the value undefined. You can check for this inside the function to handle missing values.
Click to reveal answer
intermediate
What is a default parameter value in JavaScript functions?
A default parameter value is a value assigned to a parameter in the function definition. It is used if no argument is passed for that parameter when the function is called.
Click to reveal answer
beginner
How do you write a function with a default parameter value of 10 for parameter num?
You write: <br><pre>function example(num = 10) {<br>  // code here<br>}</pre>
Click to reveal answer
What will be the value of b when calling function test(a, b) {} as test(5)?
Anull
B5
Cundefined
D0
How do you assign a default value of 100 to a parameter x in a function?
Afunction f(x <- 100) {}
Bfunction f(x: 100) {}
Cfunction f(x == 100) {}
Dfunction f(x = 100) {}
Which of the following is true about function parameters?
AParameters are placeholders for values passed to functions.
BParameters store the return value of a function.
CParameters are only used outside the function.
DParameters must always have default values.
What happens if you call a function with more arguments than parameters?
AIt causes a syntax error.
BExtra arguments are ignored unless accessed via special objects.
CThe function automatically creates new parameters.
DThe function stops running.
Which keyword is used to collect multiple function arguments into an array?
Arest parameter (...)
Bspread operator (...)
Cdefault parameter
Darguments
Explain what function parameters are and how they work in JavaScript.
Think about how functions get information to work with.
You got /3 concepts.
    Describe how to use default parameter values and why they are useful.
    Consider what happens when a function is called without some arguments.
    You got /3 concepts.