Jason Knight
2 min readJun 15, 2020

I find it odd the things other programmers oft call "cleaner" in their code. To me using the + operator for typecasting feels dirty and cryptic, and is more the type of thing I'd expect handled by minification and not directly in the "legible" source. It's an unnatural use of it where Number() would provide much cleaner, clearer, and comprehensible code.

I suspect that this is related to my first high level programming language after learning RCA 1802 Machine language (and hand compiling my own ASM to it) was Pascal, and then having spent almost a decade working in Ada. By comparison everything about C syntax -- and languages that use them like JavaScript, PHP, Java, etc -- is painfully, needlessly, and often arrogantly cryptic. It's obtuse in how intentionally obfuscated the entire wreck is.

Hence why I'm no fan of the mind-numbingly dumbass arrow functions either; where apart from one minor change in functionality I would rarely see the need for, it reeks of "wah wah, eye dunz wunna tiep teh wurd function". Or the mental-huffing-midgetry of people who use "TLA" (three letter acronyms) for everything in their code.

Though the real ugliness of arrow functions being how they've encouraged everyone to use callbacks for NOTHING dragging the performance of their scripting into the 9th circle of hell.

Oh, and cute trick, your (value % 2 != 0)? You can just (value % 2) since it returns 0 or 1. Aka loose false and true. You don't need the comparison.

Also little detail about using comma that way, it's not so much an operator as a "continue and return LAST". You can test this with return.

return 1, 2, 3; // returns 3

Which can in some cases be handy. The big thing to remember is that they are ALL run regardless of result, as they do NOT perform comparison. If anything it's more like a semi-colon that doesn't end a statement.

You can even use it inside a condition to perform operations the rest of the condition relies upon. For example you want to compare j > i * 2 when i goes up faster but j starts higher... but you don't want to multiply i * 2 more than once for performance sake.

for (var i = 1, j = 10, k; k = i * 2, j > k; i += 2, j++) console.log(i, j, k);

is functionally identical to:

for (var i = 1, j = 10, k; j > (k = i * 2); i += 2, j++) console.log(i, j, k);

or the way most people would write that:

for (var i = 1, j = 10; j > i * 2; i += 2, j++) console.log(i, j, i * 2);

Which needlessly performs the same multiply twice. In this simple example that probably doesn't matter, but the more times that result is used inside the loop, the more storing it in a variable starts to be more efficient.

Jason Knight

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse