Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript DOM Scripting By Example Adding and Removing Names RSVP Checkbox

arif khan
arif khan
2,121 Points

to work with event object inside a handler we need to pass it then how come we are accessing variables defined outside?

const in = form.getElementById('input'); form.addEventListener('submit', (e)=>{ e.preventDefault(); //we can access coz we pass it to the event handeler function const text = in.value; //didnt pass cont variable in but accessible how?? })

1 Answer

Steven Parker
Steven Parker
231,275 Points

A function always has access to variables that exist in the execution context, in addition to those passed in as arguments.

At a minimum, the execution context includes all variables defined in the global scope (except for those that may be "shadowed" by inner scope variables of the same name).