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