Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
from javascript.info
"
But if there is a return statement, then the rule is simple:
If return is called with an object, then the object is returned instead of this.
If return is called with a primitive, it’s ignored.
In other words, return with an object returns that object, in all other cases this is returned.
"
Not sure, but I think beceause as soon as you call the NameMe function you will get the object back that is returned inside NameMe. So it will only get you the name. But if you return nothing you will get "this", so the NameMe object itself.
You have a point and I agree with you about the one-liner problem (even if it's going against what I wrote three years ago).
Nowadays I don't use bracket with one-liners that can be written on the same line of the
if
, often for early exits:Otherwise, I like to use brackets mostly to make all if-statements look the same. Consistency makes things easier to read in my opinion. (And clear rules are easier for a team to follow and for tools to enforce.)
Refactoring out a function whenever there are a few lines, Uncle Bob-style, is another discussion. :-)
I would not say, that it is best practice, it is coding conventions. And in the majority of coding conventions the brackets are demanded.
I had to work without brackets and I must say since then the code without brackets is much easier to read.
The main argument is allways, that you may add a line outside the conditional block. In my expierence this never happens. And if it happens your test should fail. And if you have to add lines to a conditional block, it maybe time to refactor a methode which a catchy name.
You misspelled Coffee.
Yeah, it's mainly for brevity. Have no idea about performance, but as @Balkoth said, I'm guessing it makes very little difference.
It is an alternate - and shorter - way to write an
if
statement, so it's not faster, it's the same.I would even go so far as to say that using the brackets are best practice. It's easy to start out with a one-liner and forget to put in the brackets when you add another line to the conditionaly block.
Brackets are optional for single line if statements (but some people prefer to add them for clarity).