Functions are a kind of subroutine that performs a specific task. Like every other programming language, JavaScript has its own rules for declaring functions. Some syntax may seem familiar; however, there are a few things to notice.
The function
keyword is placed before the name of the new function to indicate that a new function is being declared. Curly braces {}
are used to indicate the function’s body, like most other languages.
function HelloWorld(args){
// your code
}
In JavaScript, we can make functions without a name called anonymous functions. In the example below, the variable HelloWorld
can lose the function declaration and be replaced by any other value.
Lambda functions are similar to anonymous functions, but they have more flexible features and syntax. An arrow function
is another of this type of function.
var functionName = (parameters) => // function body
Free Resources