From the course: JavaScript: Patterns
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Functions as first-class citizens - JavaScript Tutorial
From the course: 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.…
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.