Functions in JavaScript
Functions in JavaScript
Function names can contain letters, digits, underscores, and dollar signs
(same rules as variables).
console.log(calcAddition(6,9));
Output
15
In the above example, we have created a function named calcAddition,
This function accepts two numbers as parameters and returns the
addition of these two numbers.
Accessing the function with just the function name without () will return the
function object instead of the function result.
There are three ways of writing a function in JavaScript:
Function Declaration: It declares a function with a function keyword. The
function declaration must have a function name.
Syntax:
function geeksforGeeks(paramA, paramB) {
// Set of statements
}
Function Expression: It is similar to a function declaration without the
function name. Function expressions can be stored in a variable
assignment.
Syntax:
let geeksforGeeks= function(paramA, paramB) {
// Set of statements
}
Function Invocation
The code inside the function will execute when "something" invokes (calls)
the function: