Page 143 - CITS - Computer Software Application -TT
P. 143
COMPUTER SOFTWARE APPLICATION - CITS
function multiply(a, b) {
b = type of b !== “undefined” ? b : 1;
return a * b;
}
console.log(multiply(69)); // 69
Output
69
Calling Functions:
After defining a function, the next step is to call them to make use of the function. We can call a function by using
the function name separated by the value of parameters enclosed between the parenthesis and a semicolon at
the end. The below syntax shows how to call functions in JavaScript:
Syntax:
functionName( Value1, Value2, ..);
Example 5: Below is a sample program that illustrates the working of functions in JavaScript:
• JavaScript
function welcomeMsg(name) {
return (“Hello “ + name + “ welcome to NSTI”);
}
// creating a variable
let nameVal = “Admin”;
// calling the function
console.log(welcomeMsg(nameVal));
Output:
Hello Admin welcome to NSTI
Return Statement:
There are some situations when we want to return some values from a function after performing some operations.
In such cases, we can make use of the return statement in JavaScript. This is an optional statement and most
of the time the last statement in a JavaScript function. Look at our first example with the function named as
calcAddition. This function is calculating two numbers and then returns the result.
Syntax: The most basic syntax for using the return statement is:
return value;
The return statement begins with the keyword return separated by the value which we want to return from it. We
can use an expression also instead of directly returning the value.
Functions:
• JavaScript | Arrow functions
• JavaScript | escape()
• JavaScript | unescape()
• JavaScript | Window print()
• Javascript | Window Blur() and Window Focus() Method
• JavaScript | console.log()
• JavaScript | parseFloat()
130
CITS : IT&ITES - Computer Software Application - Lesson 37 - 46