课程: JavaScript Practice: Scope and Closures
Solution: Wrap variables in closures - JavaScript教程
课程: JavaScript Practice: Scope and Closures
Solution: Wrap variables in closures
- [Instructor] A closure gives you access to an outer function scope from inside of a function. So here we have this congratulate function that is taking in a user and we need to provide some sort of sentence here. So we'll say let sentence equal great job. So then we're going to take the contents of this sentence and make it available inside of this function so that it can combine the sentence with the user. So we're just passing that down into its own helper function. So this is our interior function. All we need to do here is say return. We'll use a template string with these back ticks and then we'll use the template to inject the sentence. We'll add a comma and then we'll add name.