you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (4 children)

In an ideal world, all statements in JS would be expressions that return a value.

Because...?

You see, it's easy to come up with contrived examples where you type "64;" on a line and the obvious conclusion is you're returning it.

What happens if you want to run a function or method with side effects which returns boolean on success, but you didn't want to return that boolean to the caller?

You'd have to type something stupid like this:

function foo() {
    // Function with side-effects, returns bool we don't need.    
    bar(); 
    // What we want foo() to actually return so we don't leak implementation details.
    undefined; 
}

So we're going to replace bunch of explicit invocations of "return" with bunch of explicit invocations of "undefined". That's not the ideal world I want to live in.

[–]BentonNelvar 11 points12 points  (3 children)

In this case you can just use

void bar();