Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript, how to continue expression on the next line

Is there a way to continue expression on the next line in JS?

const result = 'one' ? 1 :
  'two' ? 2 :
          3

turn it into

const result = \
  'one' ? 1 :
  'two' ? 2 :
          3

and turn this

return condition1 && 
  condition2 && 
  condition3

into

return \
  condition1 && 
  condition2 && 
  condition3  

So it would looks better?

It's possible to do it like that but I hope there are better way

return true &&
  condition1 && 
  condition2 && 
  condition3  
like image 551
Alex Craft Avatar asked May 10 '26 22:05

Alex Craft


1 Answers

Your first desired snippet

const result =
  'one' ? 1 :
  'two' ? 2 :
          3

is already allowed, but due to automatic semicolon insertion (ASI), the return statement must be written as:

return (
  condition1 && 
  condition2 && 
  condition3
)
like image 125
Patrick Roberts Avatar answered May 13 '26 11:05

Patrick Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!