Can i use a var of a function outside it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can i use a var of a function outside it?

Please help me Is un javascript

28th Jul 2021, 3:58 AM
Victor Emmanuel Reina Liscano
Victor Emmanuel Reina Liscano - avatar
4 Answers
+ 3
Yes. Undeclared variable will become a property of window object. https://code.sololearn.com/WwhKQUoMbXHH/?ref=app https://www.sololearn.com/post/91113/?ref=app
28th Jul 2021, 6:10 AM
Gordon
Gordon - avatar
+ 2
Victor Emmanuel Global variables can be used anywhere in JavaScript even inside any function defined in same JavaScript. Variables defined in any function can be accessed in that function, there is a way to access those variables outside function by passing as argument (parameter) to another function, from function where it's defined. It can be updated by assigning return value of another function call where variable is defined. There is no other way to access variable defined in an function. DHANANJAY PATEL
28th Jul 2021, 4:41 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 1
You can't do it. You could only use it in the inside of the function.
28th Jul 2021, 4:36 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
You can declare a global variable like this: var blankVar; Then pass the information to the variable inside the function like this: function passParameters() { **some bit of code** blankVar = **some bit of code**; }
29th Jul 2021, 4:03 AM
Anthony Johnson
Anthony Johnson - avatar