[Solved] Can someone explain me why we use parentheses around conditions in javaScript


You use parentheses around the condition because you must. The syntax of javascript demands that for if statements, the condition is wrapped in parentheses. Leaving them out is a syntax error.

If you’re asking why the language was designed to have that particular syntax instead of some other, none of us were in the room when that decision was made. So about the best we can offer you is the answer 0.sh gave in the comments: “because Brendan Eich said so”. Brendan Eich was the original creator of the javascript, and so he laid the foundations of its syntax. Whatever his motivations were for this decision, that’s the reason it is that way.

It’s possible to design languages so that the parentheses are optional, but that’s just not the way javascript was designed.

3

solved Can someone explain me why we use parentheses around conditions in javaScript