JavaScript Interesting error based on automatic semicolon insertion JS rules. Explanation required

Today I wrote code for some programming contest. When I run it I was surprised because of error. Cannot read property 'forEach' of undefined in a place where looks like "error free space".

sum = 0
            [-1,0,1].forEach(deltar =>{...});

When I add semicolon after sum variable value assignment code start to works.

sum = 0;
            [-1,0,1].forEach(deltar =>{...});

It's very curious about JS behavior what do interpreter mismatch here? how do JS mess with integer and array after it?

Here it is a full code of the function to make the complete picture of variables declaration.

function boxBlur(img) {
    let [h,w] = [img.length-1,img[0].length-1];
    let [answer,sum,tmp] = [[],0,[]]
    for(let row = 1; row < h; row += 1){
        tmp = []
        for(let clmn = 1; clmn < w; clmn += 1){
            sum = 0;
            [-1,0,1].forEach(deltar =>{
                [-1,0,1].forEach(deltac =>{
                    sum += img[row+deltar][clmn+deltac]
                });
            });
            tmp.push(parseInt(sum/9));
        }
        answer.push(tmp);
    }
    return answer;
}
Answer:1

WHAT I WANT TO DO I want to shorten my code. This Drum Play App plays sound by pressing certain keys or clicking with your mouse. It works, but the code for click events is too long because I ...

WHAT I WANT TO DO I want to shorten my code. This Drum Play App plays sound by pressing certain keys or clicking with your mouse. It works, but the code for click events is too long because I ...

  1. short code with
  2. short code with twilio
  3. shorten code in python
  4. shorten code in excel

I want to make sure that I can't push a duplicated value into an array in a React state. The duplicated value is still going in the array though. I have tried using .includes but it is not working. ...

I want to make sure that I can't push a duplicated value into an array in a React state. The duplicated value is still going in the array though. I have tried using .includes but it is not working. ...

  1. how to include duplicate values in pivot table
  2. how to include duplicate values in sql

Problem Let's make a basic list and sort it to make sure that 2 is ALWAYS first in the list. Simple enough, right? [1, 2, 3].sort((a, b) => { if (a === 2) return -1; return 0; }); Chrome ...

Problem Let's make a basic list and sort it to make sure that 2 is ALWAYS first in the list. Simple enough, right? [1, 2, 3].sort((a, b) => { if (a === 2) return -1; return 0; }); Chrome ...

I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...

I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...

  1. javascript multiple event listeners
  2. javascript multiple event handlers
  3. javascript multiple event listeners for the same event
  4. javascript multiple event listeners order
  5. javascript multiple event listeners same function
  6. javascript multiple event
  7. javascript multiple event handlers onclick
  8. javascript multiple event binding
  9. javascript event multiple functions
  10. javascript event multiple elements
  11. javascript event multiple keys
  12. javascript event multiple buttons
  13. javascript add multiple event listeners
  14. javascript prevent multiple event listeners
  15. javascript attach multiple event handlers
  16. javascript adding multiple event listeners
  17. javascript register multiple event handlers
  18. javascript remove multiple event listeners
  19. javascript add multiple event handlers
  20. javascript bind multiple event handlers