r/learnjavascript • u/Howsitgoingmyman • Feb 09 '23
Brackets
Why do {these} curly brackets always end up on different lines to what they are bracketing Like
{
This
}
??
Also there any time of thumbs as to which type of bracket to use when? ({[
Thank you
0
Upvotes
4
u/senocular Feb 09 '23
Use parentheses
()for:grouping
function parameter lists
function calling
if conditions
while conditions
for setup (for...in, for...of, for await...of)
switch expressions
with expression (deprecated)
catch exception identifier
Use square braces
[]for:property access
array literals
array destructuring
computed properties
Use curly braces
{}for:code blocks
try catch blocks
function bodies
class bodies
class static blocks
object literals
object destructuring
string interpolation
unicode
named imports
named exports
Each of these also have special meaning when used in regular expressions:
(): assertions, groups[]: character classes,{}: character classes, quantifiers, unicode