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

Statement v.s Expression

Hello everyone! In the video Jim says that:

"We can't just write a simple for loop, because like an if statement, it is a statement and not an expression. Instead we'll use the map function of the array."

I don't really understand what he means by saying that. "if" and "loop" are statements? What is a statement and what's the difference with an expression in general and in this particular example?

2 Answers

Steven Parker
Steven Parker
243,228 Points

Statements are executed and cause something to happen. Expressions are evaluated and return a value, but don't change anything.

Examples:

var sample = "test";  // this statement creates and sets the value of "sample"
6 * 3 + 11            // this expression evaluates to the value 29, but doesn't save it anywhere
amt = 12 * 2 - 7;     // both: the expression is evaluated and then the statement assigns it

For more specific answers, always provide a link to the course page.

Thank you very much!!It’s been really helpful!