Variables declared inside a JavaScript function are LOCAL to that function.
// code here can NOT use carName function myFunction() { let carName = “Volvo”; // code here CAN use carName } // code here can NOT use carName |
Local variables have function scope, meaning they can only be accessed within the function where they are declared. |
Since local variables are only accessible within their respective functions, you can use the same variable name in different functions.
Local variables are created when a function is called and are deleted once the function finishes executing.