Defining Functions with Parameters
Welcome to the "Defining Functions with Parameters" Practice Lab. In this module you will be provided with the instructions and devices needed to develop your hands-on skills.
Already have an account? Sign In »

Introduction
Welcome to the Defining Functions with Parameters Practice Lab. In this module you will be provided with the instructions and devices needed to develop your hands-on skills.
Exam Objectives
The following exam objective is covered in this lab:
- 2.5 Complete and debug a function that accepts parameters and returns a value
Lab Duration
It will take approximately 10 minutes to complete this lab.
Exercise 1 - Creating Functions with Parameters
As you know, user-defined functions can have arguments or parameters. The parameters are placed within the parentheses just after the function name. These are separated by commas. For example, a user-defined function definition with parameters will be as follows:
The data types of parameters need not be specified. The values for parameters num1 and num2 will be passed when the function is invoked.
The function mycalc(num1, num2) can be invoked as follows:
The function will display the output as 100 on execution.
In JavaScript, the function parameters are passed by value when the function is invoked. In other words, actual values are given to the parameters and not the memory locations of the parameters.
In this exercise, you will learn how to create and invoke user-defined functions with parameters in JavaScript. You will perform two tasks:
- Task 1 - You will download the Visual Studio Code workspace (Calculator) from the Intranet and create a new HTML page named Functions_param.html in the Calculator workspace.
- Task 2 - You will write JavaScript code to create and invoke user-defined functions with parameters.
Learning Outcomes
After completing this exercise, you will be able to:
- Create and invoke user-defined functions with parameters in JavaScript
See the full benefits of our immersive learning experience with interactive courses and guided career paths.