Javascript Functions — Understanding The Basics
Explore Functions in JavaScript — declaration, expressions, invocation, and more.
What is a Function?
- A function is a subprogram designed to perform a particular task.
- Functions are executed when they are called. This is known as invoking a function.
- Values can be passed into functions and used within the function.
- Functions always
return
a value. In JavaScript, if noreturn
value is specified, the function will returnundefined
. - Functions are objects.
Define a Function.
There are a few different ways to define a function in JavaScript:
A Function Declaration defines a named function. To create a function declaration you use the
function
keyword followed by the name of the function. When using function declarations, the function definition is hoisted, thus allowing the function to be used before it is defined.function name(parameters)
{
statements
}
functionname();
We can wake up the function by by simply calling the function in the HTML or can be used in input tags a JavaScript function can be return in the head section or in the the body section using the tag.
Example:
<html>
<head>
Comments
Post a Comment