News for hackers. Stuff that matters.
Re:JavaScript Hacks for Hipsters by fedlarm on Thursday October 09, 2014 @10:39AM (#8432604)
One I've never thought of using before is the: isAwesome && alert("yay");

I have used the name || "no name" operator a lot and thought to myself that it looked cool on first impression. But having something like: isAwesome() && alert("yay"); Already makes it harder to read I think. I'm curious to what others think of this one? Maybe its just because it is new to me..

Re:JavaScript Hacks for Hipsters by digibo on Thursday October 09, 2014 @12:43PM (#8433508)
I find constructs like isAwesome() && alert("yay"); confusing as well, but in our codebase it's pretty much standard to use a simple falsy check like 'callback && callback()' for optional callbacks, but we don't use it anywhere else.

To be honest, I like and use some of those, especially when writing experimental/disposable code, but otherwise I try to be gentle to less experienced developers and my future self.

As of #5 - I used to do and love this when writing unit tests. At the end of the work day, if I'm in the middle of implementing a feature, I'd commit and then write the next unit test (inevitably) sitting in my head and leave it failing. Really helps when it's Monday.

Re:JavaScript Hacks for Hipsters by byerley on Thursday October 09, 2014 @10:57AM (#8432710)
I don't think I've ever misread that style (usually the function being called makes it obvious), but it relies on short-circuit evaluation which doesn't carry over to a lot of languages - http://en.wikipedia.org/wiki/Short-circuit_evaluation

C is particularly dangerous because it will normally short-circuit, but the standard doesn't require it and in rare cases the compiler will optimize it out.

Re:JavaScript Hacks for Hipsters by JonnieCache on Thursday October 09, 2014 @10:45AM (#8432643)
I agree that it's ugly, but also in some languages you can get into trouble because of operator precedence. This is why ruby and perl have the operators `or` and `and` as well as || and &&.

http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/

Re:JavaScript Hacks for Hipsters by xyclos on Thursday October 09, 2014 @11:00AM (#8432736)
it is also useful for cross browser debugging. having a console.log() in your code running in IE will cause problems if the console isn't actually open. If you use window.console&&console.log() you can be sure that it wont hurt your code running in IE.