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 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! :)