I'd expect three times. The function foo(x) would receive the next syntactic element as its body, which is console.log(x). Not because of indentation, but because it's the next expression. If you wanted more than one expression, you would use the braces to make a block, which would group the multiple expressions into one. Then it would be consistent with the way we use blocks on if statements.
Without braces, how would the interpreter / a fellow developer know where the function ends? If you write
then how often are you expecting to see Hello logged? Three times? Four times? Zero times? An unbounded number of times due to recursion?
Some languages use whitespace or
end
, but I find the braces to be more readable and less error prone.I'd expect three times. The
function foo(x)
would receive the next syntactic element as its body, which isconsole.log(x)
. Not because of indentation, but because it's the next expression. If you wanted more than one expression, you would use the braces to make a block, which would group the multiple expressions into one. Then it would be consistent with the way we use blocks on if statements.Oh, also note that this is how fat arrows work:
Python developer disagrees. 🐍🐍🐍