Exploring functions
Functions are one of the more meaningful structures in JavaScript. There are certain characteristics that make them different from other programming languages; for example, they are first-class citizens, which means that they can be assigned to a variable, passed as an argument to another function, or returned from another function.
The basics
There are many advanced concepts related to functions, but in this section, we will just look at the basics of functions in JavaScript. We will start with the declaration, execution, and arguments using the function
keyword. Then, we will focus on arrow functions and closures.
Declaration
In essence, a function is a block of code that can be executed when it is called. In JavaScript, we can declare a function using the function
keyword. The syntax is the following:
function myFunction() { console.log("This is a function body") // code to be executed }
Execution
The function...