Variables inside of Functions

Can someone help me understand when and why variables are used inside of a function? Like in this example :

const getUserName = () => {
let name = ‘Whitney’;
return name;


const rectangleArea = (width, height) => {
let area = width * height;
return area;

Variables are what make functions re-usable under varying conditions. We seldom use a function to set a literal, such as the first example above, but in the second example we can see how variable data can be given to the function (arguments) and return a computed value using them (parameters).

Edited 1h later - grammar, mostly.


The most fundamental of all functions is the identity function, namely, a function returning its argument.

f = function (x) {
    return x

x = 1
console.log(f(x))    //  1

All other functions are built upon the construct of that simple model.