You are right to question those curly braces. They don’t do anything at all. The code inside the braces executes just the same as it would if the braces weren’t there. It’s clearly a mistake to have them there like that.
As you mentioned, it looks like somebody could have thought that the curly braces would introduce a block scope, perhaps causing a variable to go out of scope after the braces are closed. But JavaScript doesn’t have block scope for var
variables! (It does have block scope for let
, but only in the newer JavaScript engines that support let
.)
Or maybe they just thought it would be a good way to document where the variables are used. It’s not.
Adding to the humor here, the code appears to be missing the var
for _occurrenceID
entirely – so it’s probably creating a global variable unintentionally!
The way you rewrote the code without the curly braces is indeed how it will actually execute. It is a better representation of what the code actually does and is how the code should be written. (Fixing the missing var
of course…)