Java script function
Function: A reusable code that is executed by an event-driven or when it is called.
Function names are strictly case-sensitive and duplicate names produce overrides.
1. function with return value
Sometimes, we want the function to return the value to the place where it was called.
This can be achieved by using the return statement.
When you use the return statement, the function stops execution and returns the specified value.
2. Local JavaScript variables
A variable declared inside a JavaScript function (using VAR) is a local variable, so it can only be accessed inside the function. (The scope of the variable is local).
You can use local variables with the same name in different functions, because only the function that declares the variable can recognize the variable.
As soon as the function is complete, the local variable is deleted.
3. Global JavaScript variables
Variables declared outside of a function are global variables, and all scripts and functions on a Web page can access it
4. The lifetime of JavaScript variables
The lifetime of JavaScript variables begins at the time they are declared.
Local variables are deleted after the function is run.
Global variables are deleted after the page is closed.
5. Calling functions with parameters
When you call a function, you can pass a value to it, which is called a parameter.
These parameters can be used in functions.
Variables and parameters must appear in a consistent order. The first variable is the given value of the first parameter passed.
Alert (Window.calc (3,5)); window is the largest variable
<! DOCTYPE html>
<! DOCTYPE html>
Java script functions, variables, objects