Why we can access function created outside the function but cant access variable or value outside the function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why we can access function created outside the function but cant access variable or value outside the function?

JAVASCRIPT problem i faced while solving problem of creating calculator

28th Aug 2018, 9:25 AM
MOKTAN NISHAN
MOKTAN NISHAN - avatar
1 Answer
+ 2
If you want to acces a variable outside a function, make it global. https://www.sololearn.com/discuss/1465290/?ref=app var variableOne = [ "newVarone", "newVartwo", "newVarthree", 1000 ]; var variableTwo = new Var(); variable[0] = "newVarone"; variable[1] = "newVartwo"; variable[2] = "newVarthree"; variable[3] = 1000; var variableThree; function() { console.log(variableOne[1]); console.log(variableTwo[2]); console.log(variableThree = "newVar"); } Hope it helps👍
28th Aug 2018, 10:49 AM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar