JS conditional style choice?

I have two questions about style after watching Doug Crockford’s video. Aside from what works or what doesn’t, which is the correct style in modern JS?

if (condition) foo();

if (condition) {

I’m asking because of this style mentioned by Doug in the part I recap.

I like to use single line if statements. Is that a bad style still?

As long as I am asking about style can someone elaborate on what Doug means here? It looks familiar to things I have used and I want to understand the implications of why (g && g = foo); or (g && g + 7); is bad?

Two things:

  • Be wary of watching javascript videos from 10 years ago, the language changes very rapidly compared to others, and already a lot of the things that were normal then are not now.
  • in general with syntax style I would aim for what the majority of people seem to do (as it’ll make my code more readable in a team) unless it jeopardizes safety or efficiency.

Thank you! Good words. What works for the group, works for the code. :+1: