Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
oxmox2916yI prefer the one-liner...but why are you returning 3 variables? In my Point of view thats not good practice
-
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. -
@Artemix Piece of garbage indeed. Statements after return will not be ignored on the first pass :(
-
inaba46256yGood 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 -
agnibha15536y@wombat that was just an illustration.. What I meant was the way it behaves is error prone...
Related Rants
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...
rant
life of programmer
javascript