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
anonymous123
5,794 PointsWhat's the difference between a command and function in JavaScript?
these are all commands and functions: document.write(), console.log(), alert(), and prompt()
1 Answer
Steven Parker
243,266 PointsAll four of your examples are functions. I'm not used to seeing the word "command" used to describe JavaScript, I'm guessing you mean what's more commonly called "statements". Statements generally use special keywords like "if", "while", "break"; or operator symbols like "=". They make something happen directly.
Functions, on the other hand, refer to another area of code which the system must go to and run before coming back to the place where the function was called. Functions have names that are decided on by the person who codes them, and are not special to the language like statement words.
Does that cover what you wanted to know?
anonymous123
5,794 Pointsanonymous123
5,794 PointsIt almost does. I just still dont know what a command is. If a command is a statement than you covered everything I wanted to know.
Commands are talked about a lot in the JavaScript Basics course I am taking but the teacher never explains what it is.
quotes of the teacher using the word command:
"A programming language's syntax is the different commands, special words, and punctuation you use to put together a program."
"Alert is a command that's built into the browser. It opens a dialogue box and displays a message."
Steven Parker
243,266 PointsSteven Parker
243,266 PointsIt seems like "command" is being used to broadly refer to any language element that makes something happen. For example, "alert" is a function that is built into the browser. But in the other quote it seems like "command" is referring to language statements. I'm guessing that terminology was just being used until the concepts of statements and functions could be more fully explained.