short ≠ clean≠ readable
short
clean
readable
2 Instead of
a = { [c > d ? 'foo' : 'bar']: 'apple' };
it's better to split it into couple lines
const key = c > d ? 'foo' : 'bar'; const a = { [key]: 'apple' };
4 might be even cleaner
const { x: a, y: b } = foo;
6 seems overcomplicated, maybe something like
const [a, b, c, d] = ['a', 'b', 'c', 'd'].map(document.getElementById)
7 questionable, I'd say if construction is easier to understand, especially for juniors joining the project
if
8 use ?? instead of || - that way you'll not override 0 value
??
||
0
9 less known JS feature - you may use underscore to divide long numbers
const a = 1_000_000; console.log(a); // 1000000
bonus just use a debugger or create an IDE snippet.
So, if initially a has several properties
a
let a = { foo: 'some', bar: 'example' };
Then after
c > d ? a.foo = 'apple' : a.bar = 'apple';
a will have same amount of properties. But after
It will hav only 1 property. It's not even the same!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
short
≠clean
≠readable
2 Instead of
it's better to split it into couple lines
4 might be even cleaner
6 seems overcomplicated, maybe something like
7 questionable, I'd say
if
construction is easier to understand, especially for juniors joining the project8 use
??
instead of||
- that way you'll not override0
value9 less known JS feature - you may use underscore to divide long numbers
bonus just use a debugger or create an IDE snippet.
So, if initially
a
has several propertiesThen after
a
will have same amount of properties.But after
It will hav only 1 property. It's not even the same!