JavaScript Worksheet
Name:
Choose the correct answers even if there are multiple
1. Allow functions to accept input and perform a task using the
inputs.
a) Global Namespace
b) Parameter
c) Argument
d) Blocks
2. A reusable block of code that groups together a sequence of
statements to perform a specific task.
a) Function
b) Identifier
c) Argument
d) Blocks
3. You call a function by typing the function name followed by
parentheses.
a) True
b) False
4. Arguments can be passed to the function as values or variables.
a) True
b) False
5. What is the syntax for creating a function in JavaScript named as
sum?
A) function = Geekfunc()
B) function Geekfunc()
C) function := Geekfunc()
D) function : Geekfunc()
6. Which of the following is NOT a valid component of a function
declaration?
a) Function keyword
b) Function name
c) Pair of Square Braces
d) Pair of Curly Braces
7. Where is the correct place to insert a JavaScript?
a) The <head> section
b) The <body> section
c) both the <head> and <body> section are correct
d) The <html> section
8. Choose the correct code to be inserted at line 4 in order to invoke
the function.
thisfun=function lfc(x){
alert(x*x);
}
// line 4
A. thisfun(10)
B. lfc(10)
C. function thisfun(10)
D. None of the above
9.
What is the name of this function?
a) function
b) spin()
c) 3 turnLeft();
d) spin();
10.
Is this Function written correctly?
a) True
b) False
11. Given the following code:
const square = function (number) {
return number * number; };
const x = square(4);
Which is considered as the function call?
a) square(4)
b) return number * number
c) function (number { .... }
d) const x and const square
12. Given the following code:
const square = function (number) {
return number * number; };
const x = square(4);
Which is considered as the function declaration?
a) square(4)
b) return number * number
c) function (number { return number * number; }
d) const x and const square
13. If a function happens to take arguments and you don't provide
any arguments as part of your function call, provide too few
arguments, or provide too many arguments, things can still work.
a) True
b) False
14. _________ a function means to execute its body.
15. The same rules in naming variables are applied in naming your
functions.
a) True
b) False
16. What is the correct syntax for declaring a function named
`myFunction` in JavaScript?
a) function myFunction() {}
b) declare myFunction() {}
c) def myFunction() {}
d) create myFunction() {}
17. What is the term for the values passed to a function when it is
called?
a) Parameters
b) Arguments
c) Variables
d) Constants
18. In the following function, what is the parameter?
function greet(name)
{ return "Hello, " + name; }
a) greet
b) name
c) "Hello, "
d) Return
19. Consider the following code:
var x = 10;
function example() {
var x = 20;
[Link](x); }
example();
What will be printed to the screen?
a) 10
b) 20
c) 30
d) undefined
20. How can you ensure a function returns a value in JavaScript?
a)By using the `return` keyword followed by the value
b)By using the `output` keyword followed by the value
c)By using the `send` keyword followed by the value
d)By using the `give` keyword followed by the value
21. What will the following code output and why?
function calculateArea(length, width) {
if (width === undefined)
{ return length * length; }
return length * width; }
[Link](calculateArea(5));
a) 25, because only one argument is passed, so it calculates the area
of a square
b) 0, because width is undefined
c) NaN, because width is not a number
d) Error, because width is not provided
22. What is the purpose of a return statement in a function?
a) To stop the execution of the function and return a value
b) To declare a variable
c) To call another function
d) To log a message to the console
23. Given the following code, what will be the output and why?
[Link](square(4));
var square = function(n) {
return n * n; };
a) 16, because the function is called with 4
b) Error, because `square` is not a function
c) undefined, because `square` is not defined
d) NaN, because `n` is not a number
24. Which of the following statements about parameters and
arguments is true?
a) Parameters are the actual values passed to a function, while
arguments are the variables listed in the function definition.
b) Arguments are the actual values passed to a function, while
parameters are the variables listed in the function definition.
c) Parameters and arguments are the same and can be used
interchangeably.
d) Neither parameters nor arguments are used in JavaScript
functions.
25. What is the purpose of the parentheses ‘()’ in a function call?
A) To define the function
B) To pass arguments to the function
C) To declare a variable
D) To comment out the function