课程: JavaScript: Patterns

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Functions as first-class citizens

Functions as first-class citizens - JavaScript教程

课程: JavaScript: Patterns

Functions as first-class citizens

- [Instructor] You may have heard of this term functions as first-class citizens from time to time and wonder what does that mean? It means that functions can be treated like a variable. Meaning, they can be passed as arguments to other functions. It can be assigned as a value to a variable or even return in a function. It means that function is a first-class citizen. Let me demonstrate. So, let's go back to our index.js and we're going to write some code. So, feel free to keep this if you want to but I'm going to remove this and then start by creating a function. So, we're going to do const calc equals and we're not going to pass any arguments, and then returns a function here. So, this function will return four times three, like so. And then, what we're going to do is use this function and then use it as a variable. So, let's go ahead and create a new variable aNumber and then pass that function inside of that variable.…

内容