Skip to content
Advertisement

Not able to change value of Global var from inside function

I tried using this solution but it didn’t work for me. In my case I am trying to save a variable using 1 function and call it from another

JavaScript

The save_postal_code function logs the correct value, but the get_postal_code function doesn’t. I don’t know what I am doing wrong.

Advertisement

Answer

You’re redeclaring postalcode inside save_postal_code() instead of updating its value.
The code needs further revision, but that’s outside the scope of this answer.
To have postalcode updated inside save_postal_code(), try:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement