javascript / beginner
Snippet
Named Function Declarations
A function declaration defines a reusable block of code with a name. Unlike arrow functions, these are hoisted, meaning they can be called before they are defined in the code.
snippet.js
1
2
3
4
5
function calculateTotal(price, tax) {return price + tax;}const total = calculateTotal(100, 19);
Breakdown
1
function calculateTotal(price, tax)
Defines a function named 'calculateTotal' that accepts two parameters.
2
return price + tax
Sends the calculated result back to wherever the function was called.