From the course: JavaScript: Closures
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Nesting functions - JavaScript Tutorial
From the course: JavaScript: Closures
Nesting functions
- [Instructor] Another building block of closures is nested functions. In functional programming, we often work with a set of independent functions. In object-oriented programming, we work with individual functions as methods of an object. In order to create a closure though, we nest functions, declaring a function within another function. We refer to the nested function as the inner function or the child function. We refer to the function the inner function is nested within as the outer function or the parent function. A function name has scope, just like a variable name. So creating a function within another function means that the inner function has local scope and is not available outside of the outer function. So in the script.js start file for this video, I'm building out our function that stores and updates the number of times an interface button has been clicked. And right now, my code logs the state of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.