- 1

Как сделать глобальной переменную, которая находится в функции? #js

#javascript Как сделать глобальной переменную, которая находится в функции?

30th Aug 2017, 6:55 AM
davidthegreat
davidthegreat - avatar
10 ответов
+ 7
don't use the var keyword then it will leak the var from the function scope to the global scope. edit: this is not recommended method if possible declare variables with var keyword. https://code.sololearn.com/Wr989n0MDAHh/?ref=app
30th Aug 2017, 8:59 AM
Lord Krishna
Lord Krishna - avatar
+ 7
really odd.. works fine for me.
30th Aug 2017, 9:53 AM
jay
jay - avatar
+ 7
i didn't know assigning console to a var will fail on es5 your android may be 4.4.4 kitkat or lower i guess. check now and speak...
30th Aug 2017, 9:54 AM
Lord Krishna
Lord Krishna - avatar
+ 6
web codes are processed on your mobile device not on server.
30th Aug 2017, 9:44 AM
Lord Krishna
Lord Krishna - avatar
+ 5
translation: How do I make a global variable that is in a function? #js
30th Aug 2017, 7:27 AM
jay
jay - avatar
30th Aug 2017, 8:40 AM
jay
jay - avatar
+ 5
@AxReal using var keyword inside the function will make the var available just to the function scope and not global scope. try my code declare the var hi in function you will understand.
30th Aug 2017, 9:24 AM
Lord Krishna
Lord Krishna - avatar
+ 5
lol
30th Aug 2017, 9:52 AM
jay
jay - avatar
+ 1
yes!
30th Aug 2017, 8:04 AM
davidthegreat
davidthegreat - avatar
+ 1
заюзай var. var a = 1; var сделает переменную доступной вне функции. //не уверен, что это ещё работает. но лучше возвратить переменную. var i = 1; function test(){ var i = 2; return i; } i = test();
30th Aug 2017, 8:47 AM
404 User