Nice list, even though I wouldn't call these code snippets hacks but shortcuts?
Couple of things to note.
Hack # 1: !! is called a double bang. I don't use it as it looks a bit weird. I prefer to use Boolean().
Hack # 11. example you provided for tagged template literals could be better as it just outputs what was passed. Looks like a copy of Wes Bos' article back in 2016:
Simply note, that #21 is more readable (for me both is good), but not easier for PC.
In case of XOR swap we working with numbers as bits represented in memory. In case of array swap we created 2 arrays.
Nice list, even though I wouldn't call these code snippets hacks but shortcuts?
Couple of things to note.
Hack # 1:
!!is called a double bang. I don't use it as it looks a bit weird. I prefer to useBoolean().Hack # 11. example you provided for tagged template literals could be better as it just outputs what was passed. Looks like a copy of Wes Bos' article back in 2016:
Hack #21. swapping values is much easier this way:
Hack #23. converting the way you do it can cause issues if variable holds non numerical characters. Prefer .
parseIntover plus.Hope this helps!
Simply note, that #21 is more readable (for me both is good), but not easier for PC.
In case of XOR swap we working with numbers as bits represented in memory. In case of array swap we created 2 arrays.
You're right but it only creates one array actually: a temp array
[b, a].JS then destructures it to assign values to a and be respectively.
This is what code looks like after being transpiled:
Yes, it uses more memory but we're talking about 2 numbers here so the diff in memory footprint is very minimal and not worth loosing readability.