Arrow function - lack of curly brackets in single line block

When writing an arrow function with a single line in the function block, the block will run 4 times if curly brackets are missing.

e.g:

web.init();
web.open(‘website 1 url’);
web.execute(()=> {
window.open(‘website 2 url’)
});

In this case- opens website once

web.init();
web.open(‘website 1 url"’);
web.execute(()=> window.open(‘website 2 url’));

In this case- opens four tabs of website 2

btw - couldn’t write real url since this forum doesn’t allow new users to post more than 2 links in a thread

Omitting curly brackets in this specific case is identical to adding a return before window.open, so the following two expressions are identical:

web.execute(() => window.open('http://www.google.com'));

is identical to:

web.execute(() => {return window.open('http://www.google.com');});

When this executed, web.execute will run window.open in the browser and will try to return the value returned by window.open.
However, window.open returns an object which cannot be serialized and passed back from the browser. Trying to return un-serializable objects might lead to some strangeness, like multiple tabs opening/closing in this case.

Why 1st variant works then? Because it doesn’t return anything:

web.execute(()=> { window.open(‘website 2 url’)});

is identical to:

web.execute(()=> { window.open(‘website 2 url’); return; });