9
agnibha
6y

You know why i hate JavaScript?

Instead of writing

return x.y.z;

I wrote

return
x
.y
.z;

Just for making the code look clean
and everything broke...

Comments
  • 3
    I prefer the one-liner...but why are you returning 3 variables? In my Point of view thats not good practice
  • 7
    @oxmox ? Its a chain.. Its returning z from y from x.
  • 8
    To be honest this looks not clean to me. It looks like a waste of space.
  • 4
    This happens because it is possible to omit ; in Javascript. But in reality, statements should finish with ; and interpreter puts that semicolons itself, if it thinks that you forgot them.

    That is the exact case happened to you. JS interpreter converts your code to :

    function foobar(){
    return;
    x
    .y
    .z;
    }

    Which will of course return undefined.

    return x
    .y
    .z;

    Works.

    Also,

    return (
    x
    .y
    .z;
    );
    Will work.

    I don't like this approach of JS. Why is it not already mandatory using it, at least on strict mode ? Not using semicolons can always lead to break the code while minifying it.
  • 0
    @Artemix Piece of garbage indeed. Statements after return will not be ignored on the first pass :(
  • 3
    Good thing that it doesn't work since it wouldn't have been cleaner at all compared to keeping x and y on the same line and newlines for z and beyond

    Essentially what you're saying is you don't like JS because it forces you to write cleaner code by accident
  • 0
    why not
    return x.y
    .t
  • 0
    @wombat that was just an illustration.. What I meant was the way it behaves is error prone...
  • 0
    go scala or Haskell and every is clean for you
  • 2
    Asking for errors then bashing the language for it, typical stupidity.
Add Comment