![]() The Javascript engine uses more CPU cycles running it and has to allocate more memory to store all that extra state, and even worse, the garbage collector now has a whole mess to clean up afterwards that doesn't get used ever again. finally dumps the object, assigning the values to the local scope.spreads and reassigns the object every time into yet another new object.iterates over that new array with a new function.The "wrong" example does 4 simple assignments, the Javascript engine will be able to optimise these 4 lines really easily. Snippet 6 has been mentioned several times, but the "correct" example is not only more complicated, but actually far less efficient. Snippet 8 is another where I would far prefer to read the first, "wrong" example and would understand it straight away. ![]() A nice, clear if statement would've been fine. However the assignment within the ternary (the example of "wrong" code) is also the type of thing I'd consider overly complicated. ![]() Snippet 2 took me long enough to understand what was going on that I'd probably just flag it without going any further to even check if the logic was correct. However most of these are trick shot one liners that I'd probably point out as being too fiddly if I saw them in a code review. The fact Javascript can do these things is probably worthwhile knowing to be more comfortable with the language. I think these are great easter eggs one might use for code golf.
0 Comments
Leave a Reply. |