September 2024
Intermediate to advanced
743 pages
27h 48m
English
You can use functions to group source code into reusable code blocks.
JavaScript offers several ways to define functions. First, in a function declaration, you can introduce a function with the function keyword, followed by the name of the function and a pair of parentheses. You can then write the logic to be executed (or the statements) in curly brackets in the function body.
Listing 4.18 shows a simple example of creating a function using a function declaration.
function printNumbersFrom1To10() { for (let i = 1; i <= 10; i++) { console.log(i); }}
Listing 4.18 Creating a Function Using a Function Declaration
Alternatively, functions can be created using function ...
Read now
Unlock full access