Functions
Functions are one of the most powerful and essential notions in programming. Functions like mathematical functions perform transformations, they take input values called arguments and return an output value.
Functions can be created in two ways: using function declaration
or function expression
. The function name can be omitted in function expression
making it an anonymous function
. Functions, like variables, must be declared. Let's declare a function double
that accepts an argument called x
and returns the double of x :
Note: the function above may be referenced before it has been defined.
Functions are also values in JavaScript; they can be stored in variables (just like numbers, strings, etc ...) and given to other functions as arguments :
Note: the function above may not be referenced before it is defined, just like any other variable.
An arrow function is a compact alternative to traditional functions which has some semantic differences with some limitations. These function doesn't have their own bindings to this
, arguments
and super
, and cannot be used as constructors. An example of an arrow function.
The this
keyword in the arrow function represents the object that defined the arrow function.
Last updated
Was this helpful?