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

why does javascript use parentheses and not curly braces?

Why?

1 Answer

Reuben Varzea
Reuben Varzea
23,182 Points

In what context are you referring to? For functions, JavaScript seems to use the pretty standard declaration paradigm of pass parameters in parenthesis, while the actual code block of the function is contained within curly braces. Also, even in conditionals, it uses both.

Hi Reuben!

Thanks for that! I just finished the css basic and from what I gather, css uses mostly curly braces to write declarations. ex.

ul { list-style: none; }

however, JavaScript uses parentheses - ex.

alert("Hello from Treehouse"); document.write("<h1> Welcome to JavaScript Basics </h1>"); alert("Thanks for Visiting.");

I just started the JavaScript course so the answer to my question may be answered in the later videos.

Reuben Varzea
Reuben Varzea
23,182 Points

Ah, ok.

Yeah, just view both parentheses and curly braces as being ways of grouping bits of code together. Some languages might use one or both. In fact, I think even in CSS, there are some functional pseudo-classes that introduce the use of parentheses (but only worry about stuff like that when you get to it).

You WILL see curly braces introduced in videos as you move ahead... like when you get to conditional logic, that combines both. Looks like this:

if (CHECK-TO-SEE-IF-SOMETHING-IS-TRUE) { go-ahead-and-run-this-code; };

Keep at it, and good luck! :)