What is function?
*Functions are reusable code blocks designed for specific tasks.
*It executed only when they are called.
*Functions are fundamental in all programming languages.
Why use function?
Code reusable
Modularity
Readability
Maintainability
In functions, parameters are placeholders defined in the function, while arguments are the actual values you pass when calling the function.
Example:
function sayHello() {
return "Hello World";
}
let message = sayHello()
Functions are defined with the function keyword:
followed by the function name
followed by parentheses ( )
followed by brackets { }
Function Input and Output
The most useful functions work like this:
Parameters - some values are sent to the function
Arguments - some values are received by the function
Function Code - some work is done inside the function
Return Output - some value is returned from the function

Top comments (0)