Functions – Declaring

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Functions – Declaring

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does 'function' declare a reusable block of code?
A Yes
B No
2. Does a function need parentheses after its name?
A No
B Yes
3. Must 'function' be written in lowercase?
A Yes
B No
4. Does calling a function require parentheses after its name?
A No
B Yes
5. Are JavaScript function names case-sensitive?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1function greet() { ... } A()
2greet(); BRuns the code inside the greet function
3The keyword used to declare a function Cfunction
4Follows a function's name in its declaration DDeclares a reusable function named greet
5Function greet() { console.log("Hi"); } EWrong - missing the parentheses after the function name
6function wave { console.log("Wave"); } FWrong - 'function' must be lowercase

Definitions

function

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
________ greet() {
2.
function greet_) {
3.
________ sayBye() {
4.
function sayBye_) {
5.
greet_);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Function greet() {
B console.log("Hi");
C }
Question 2
A function sayHi() {
B console.log("Hi");
C }
D sayhi();
Question 3
A function wave {
B console.log("Wave");
C }
Question 4
A function jump() {
B jump;
C console.log("Jump");
D }
Question 5
A function run() {
B console.log("Run")
C }

Answer Key

Functions – Declaring
Section A: Quick Questions
Q1
A — Yes
Q2
B — Yes
Q3
A — Yes
Q4
B — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
function greet() { ... } → Declares a reusable function named greet
Q2
greet(); → Runs the code inside the greet function
Q3
The keyword used to declare a function → function
Q4
Follows a function's name in its declaration → ()
Q5
Function greet() { console.log("Hi"); } → Wrong - 'function' must be lowercase
Q6
function wave { console.log("Wave"); } → Wrong - missing the parentheses after the function name
Section C: Definitions
Q1
function — Declares a reusable block of code with a name, which can be run later by calling it.
Section D: Fill in the Blanks
Q1
function greet() {
Q2
function greet() {
Q3
function sayBye() {
Q4
function sayBye() {
Q5
greet();
Section E: Spot the Error
Q1
A — 'function' must be lowercase - a capital F causes an error.
Q2
D — Function names are case-sensitive - it should be sayHi(), not sayhi().
Q3
A — A function declaration needs parentheses after its name.
Q4
B — Calling a function needs parentheses: jump().
Q5
B — This line is missing a semicolon, but that's not required in JS.