This article mainly introduces the basic tutorial for using JavaScript functions. it is the basic knowledge of getting started with JavaScript. if you need it, you can refer to the function as a set of reusable code, it can be called anywhere in the program. This eliminates the need to write the same code again and again. This will help programmers write modular code. You can divide large programs in some small and easy-to-manage functions.
Like any other advanced programming language, JavaScript supports all the features required to write modular code using functions.
You must have seen the functions of alert () and write () in the previous chapter. We use these features again and again, but they have been written only once in core JavaScript.
JavaScript allows us to write our own functions, and this section describes how to write our own functions in JavaScript.
Function definition:
Previously we used functions, so we need to define a function. The most common method to limit JavaScript functions is to use the function keyword, followed by a unique function name, a list of parameters (which may be empty), and a statement block surrounded by braces. The basic syntax is as follows: