JavaScript Function
What is Function?
A function
is a collection of statements, either named or unnamed (anonymous), that can be called from elsewhere within a JavaScript program.
Functions can accept arguments, which are input values passed into the function. Within a function, those arguments passed into the function can be acted upon and the results returned to the caller of the function via a return value.
When to Use Function?
Functions are perfect when you have something that needs to happen multiple times within a program. Rather than defining the same code multiple times, you can use a function to perform that action.
Function without Arguments
Example
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
parameter1, ..., parameterN | Optional | Specifies the values which will be passed by the function call. |
Assign Function to a Variable
Example
Function with Argument
Example
Passing Array as Argument
Example
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.