top of page
zczc.png

Local Referencing Environments

Local variables can be stacked dynamically. The advantages of local variables are they support recursion and the storage for local is shared among some subprograms. The disadvantages are allocation, and de-allocation needs to be initialized by time, contains of indirect addressing, and subprograms cannot be history sensitive. Local variables can be static, and the advantages and disadvantages are the opposite of those stack dynamic local variables.

 

In our case, React.js is a dynamically typed language, this means React.js does not require the explicit declaration of the variables before they’re used. The JavaScript local variables are those which are declared inside a BLOCK or FUNCTION only. Local variables can only be used within the block or the function which they are created in. Each block may use local variable with the same name so in different blocks with the same name is allowed. Local variables are also erased once a specific function has been run and/or accomplished (GeeksforGeeks, 2023).

In this example, we will see the declaration of local variables and access them. A variable named course is declared inside a function and the printed value is in the console.

image.png

In this example, the local variables will be declared with similar names and try to access them. A variable named course is declared and initialized inside two different functions. We get two different values in the console and at last undefined is printed because the variable is not initialized outside the functions.

image.png

Sample Code for the formal parameter in our sample application

image.png

newEvent is a local variable created within the handleEventSubmit function to store event data.

- Rishma Devi A/P Sivaraj
bottom of page