Concise syntax for javascript if statements without curly brackets

Viewed 1567

So pragmatically, I've got a quick and dirty answer to what I'm looking for here. But why isn't using that a good idea? Why can't I find any formal documentation of it? Is it not part of the spec and standard? Is it not widely supported? Is it just because minification could break code using that syntax?

If you could point me to more comprehensive docs of the feature, I'd appreciate that. What defines the contents of the if block? Is it indentation based? If it was, that'd be interesting.

On another note, is there something similar to this syntax for if statements in PHP? I can swear that I've seen them being used here and there, but I can't find any examples off hand. Am I just crazy and it actually doesn't exist in PHP, or can those types of if blocks be used in PHP? Does such an if block support having an else as well, both in JS and PHP?

It seems that there's an indentation based one as well as a single-line based syntax as well. What can you tell me about the following?

if(condition) do_some_statement();

Thanks

5 Answers
Related