Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Introducing JavaScript Your First JavaScript Program

program is not a set of statements, we can't apply set properties on it, shouldn't it be a collection of statements ?

If we apply set properties on a program, program flow will get changed and it will not work as it is supposed to !!

2 Answers

Just in case this helps anyone else, I suspect the OP may have moved on by now, but... I'm guessing the OP may be ESOL? Or at least not accustomed to standard American usage. Yes, a mathematical set is a defined collection of distinct objects in which order is irrelevant. This is not referring to a program in terms of being a mathematical set, so the requirements, such as the order, and the operations you can perform on it aren't applicable. "Set" can be a simpler synonym for "collection", and generally can't be assumed to mean a set in the math sense when you're talking about it outside that context. A program's statements are definitely ordered, but they're still a set, they're just not that kind of set.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,689 Points

Hi Hitesh.

The default flow for any JS program is top to bottom. Unless you use things like functions, while loops and condition statements, the program will always just run one statement after the other from top to bottom. The only way you can change this is if you run certain actions based the value of a variable or an input prompt.

Sorry if all this sounds confusing. Just for now know that JS programs always run from top the bottom of your scripts.

i understand that very well, In the video i heard "program is a set of statements" and i found it contradicting as set is a well defined collection of distinct objects with few properties like {a, b} = {b, c} and as in programs we can not just move statements up or down , so basically a program is collection rather than a set of statements. I think i'm right !