why do you need functions in your application in its simplest term a function is a custom complex type you can create on your own to:
- add custom functionlity
- create a new tye of data
- manipulate data
- group related functionalities
example:
let a=2,
b= 3
const sum = a+b
console.log(sum) // 5
// introduce a function:
function add(a,b){
return a+b
}
console.log(add(4,5)) // 9
console.log(add(7,5)) // 12
console.log(add(17,5)) // 22they have the keyword function in most cases, and they are hoisted by default.
they can be used before being defined
add(500,600,809)
function add(a,b,c){
console.log(a+b+c);
}variadic: they take arguments
function add(a,b,c){
console.log(a+b+c)
} // a variadic function that takes 3 arguments - a,b,cnon variadic: they do not take arguments
function add(){
let a,b,c = 3,4,6
console.log(a+b+c)
}you cannot use them before definition