0

How can I access a variable in another function

I have been trying to access a variable which resides in a function from another function but I haven't had any lucks with that. I tried declaring the variable outside the functions but it didn't workout. So I'm wondering if there's a way particularly of achieving this?

3rd Jun 2018, 10:03 PM
Ernest Paul
Ernest Paul - avatar
4 Antworten
+ 3
Sound like you asking about javascript scope. https://www.w3schools.com/js/js_scope.asp
4th Jun 2018, 12:16 AM
ODLNT
ODLNT - avatar
+ 2
Is there some code you share with us, as an example of what you are trying to accomplish?
4th Jun 2018, 8:25 AM
ODLNT
ODLNT - avatar
+ 1
5th Jun 2018, 12:45 AM
ODLNT
ODLNT - avatar
0
I know the scopes; global and local variables. The issue here is, when I declare a variable(locally) in a function is there any way I can access that variable in another function? I know when you declare a variable in a function, it is accessible to only that function and no any other. I tried declaring the variable and writing the statement outside the functions (globally) but the function couldn't access it.
4th Jun 2018, 8:05 AM
Ernest Paul
Ernest Paul - avatar