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

Question about Variables vs Functions and Conditional Statements

I understand, basically, what the definition of these three types of syntax are. What I'm wondering, is whether or not functions are variables, and whether conditional statements are functions. Or are conditional statements also variables but not functions?

To put it another way: is there a kind of language categorization here? Is "variable" an umbrella statement, which functions and conditional statements reside under? If so, are conditional statements a separate type of "variable" than functions, or might they in turn reside under the function umbrella, in the same way that functions might reside under the variable umbrella?

Or do they have nothing to do with each other and therefore completely separate terms?

example: A rectangle is a type of square, which is in turn a type of shape. Square and circle are under the shape category, but are otherwise unrelated.

Hope that made sense, hope someone has an answer for this!

3 Answers

They don't really have anything to do with each other. if tests for a boolean value, and variables assign values. Functions use variables and conditionals to do stuff, but they don't share a parent/child/sibling relationship.

Functions, variables and conditionals can all be expressions, they all return something. Variables are essentially a space saver in your program, you set aside a little piece of memory for whatever you store in that variable, which could be a function, or a value, or a conditional. But functions and conditionals don't necessarily save space, I can create an anonymous user function that runs once but isn't saved for later access. The same is true of conditionals. A function or conditional can be set to a variable, but this isn't always the case. It's more like boxes and coins, I can put a coin in my box but not all boxes are going to have coins in them.

Thank you so much guys! That works for me.