I GOT ERROR WHEN CALL FUNCTION JS (SOLVED) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I GOT ERROR WHEN CALL FUNCTION JS (SOLVED)

Check my code bits and go to js please read my question, how to call remove() in function2() but remove() is in the function1() : const function1 = () =>{ const remove = () =>{ ...... } } const function2 = () =>{ //my question is how to call and process remove() in here please help me } https://code.sololearn.com/W18tqk4U7kmO/?ref=app

11th Jun 2021, 7:08 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
2 Answers
+ 1
what you declare/define in a function belong to that function scope (closure)... scopes are accessible from same or child scopes (of functions defined inside initial scope) lowest level scope (accessible from anywhere) is the 'global' scope, unless you doesn't define same variable/function name in local scope however, stuff defined in global scope belong as property of global object 'window' (in browser context), so global stuff is always accessible through window object (either by using dot notation or square brackets notation -- key is the variable/function name)... unless you doesn't override 'window' in local scope ^^ you can't access function defined in function1 from function2, unless you kind of export it to the global scope: const f1 = () => { const g1 = () => { /*...*/ }; window.any_name = g1; }; const f2 = () => { any_name(); }; more on scopes & closures: https://developer.mozilla.org/en-US/docs/Glossary/Scope https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
11th Jun 2021, 11:20 PM
visph
visph - avatar
0
please check my code bit first
11th Jun 2021, 7:23 PM
hafidz ridwan cahya
hafidz ridwan cahya - avatar