JavaScript functions
A function is a group of reusable code that can be called anywhere in your program. This makes it unnecessary to write the same code over and over again. It helps programmers write modular code. Functions allow a programmer to divide a large program into small and manageable functions.
Like any other high-level programming language, JavaScript also supports all the features needed to write modular code using functions. You have seen functions like alert () and write () in the previous chapters. We have used these functions many times, but they have only been written in core JavaScript.
JavaScript also allows us to write our own functions. This section explains how to write your own functions in JavaScript.
Function definition
Before we use a function, we need to define it. The most common method for defining a function in JavaScript is by using the Function keyword, followed by a unique function name, a list of parameters (which may be blank), and a block of statements surrounded by the brackets.
Syntax
Simple syntax is as follows:
You should read it
- Call the function by pointer in C ++
- Call the function by value in C ++
- Function in programming C
- Call the function by reference in C ++
- PHP functions
- The ord () function in Python
- Int () function in Python
- Getattr () function in Python
- The function id () in Python
- The input () function in Python
- Python function parameter
- Zip () function in Python
Maybe you are interested
Difference between function and formula in Excel
8 little-known Excel functions that can save you a lot of work
How to use the NORMDIST function in Excel - Function that returns the distribution in Excel
Date functions in Excel, DAY, WEEKDAY, MONTH
How to use the SUMIF function in Excel to calculate the sum based on conditions
How to use the Round function in Excel to round numbers and process data