Functions are blocks of code that perform an action and may return a value. Functions can be customized based on your needs and can be used to make your code more efficient and modular.
In this tutorial, we’ll explore the basics of functions: how to define a function, how to call a function, and when they may be useful.
Function Declarations define a named function. In order to define this type of function, you should start your code with the
function keyword, followed by the name of the function.Function names follow the same rules as variables — they can use leers, underscores, numbers, and are often written using camel case. Then, after the variable name, you’ll include a set of parentheses, where optional parameters can be held. We’ll get to those later in the article.
Then, like a for or an if statement, the code of the function will be in curly braces.
Another way of declaring a function is to create a function expression. We can do so by assigning a function to a variable.
So, we need to make use of parameters. If we add a
name parameter to our JS function, then we can print any name to the console through our function.
Calling or invoking of function.
Overall, a function is a block of code that can perform an action and return a variable. Functions are useful if you have multiple lines of code that you may need to execute many times throughout a program.
Instead of writing those multiple lines of code every time you need to use them, you can add them to a function and call the function when you need to run the code, and pass the values you need to use into your function.
I AM SURE YOU GOT VALUE!!!!!