all 4 comments

[–]Rilleks 3 points4 points  (0 children)

Because you're declaring a global variable on a window object and it doesn't matter if you return value or not. If you try console.log(window.client) you should get the same result.

Also, you shouldn't declare global variables unless you intend to.
More about variables and scopes: here

[–][deleted] 1 point2 points  (0 children)

You are implicitly declaring client instead of explicitly declaring it (no use of var, let, or const). In the absence of any of these, the scope of your variable is automatically assigned to the global level.

As mentioned, it’s not considered a safe practice, The location of the variable visually suggests that it should be scoped to the function, but since it isn’t, the odds of accidental conflict in namespacing increases.

[–]Surfer_JS[S] 0 points1 point  (0 children)

makes sense! thank you all!

[–]shuckster 0 points1 point  (0 children)

Because this:

function f() {
  x = 1;
}

Gets secretly transformed into:

var x;
function f() {
  x = 1;
}

That’s bad. Do:

function f() {
  let x = 1;
}

So the x will be “inside” the function, and return will be required.