Extend zeroes in a matrix
From a short review;

You probably want to encapsulate if(matrix === null || matrix.length === 0) into an isValidMatrix function for re-use
I would drop the whole i/j thing and go for variables named after row and col
I would collect all the rows and columns with a 0 in one set of loops, and then clear the matrix based on the collected rows and columns in another set of loops.
let only declares in the block, so the for(i=0; i&lt;matrix.length; i++){ creates a global i
I much prefer function setFlag(matrix, i, j) { over const setFlag = function(matrix, i, j) {

This is my current proposal, I did not test it, but you should get the gist of it;
//This does not catch everything, but it'll do
function isValidMatrix(matrix){
  return !(!matrix || !matrix.length);
}

function setZeroes(matrix) {
  
  if(!isValidMatrix(matrix))
    return [];
  
  const rows = [], cols = [];
    
  for(let row = 0; row &lt; matrix.length; row++){
    for(let col = 0; col &lt; matrix[row].length; col++){
      if(matrix[row][col] === 0){
        rows.push(row);
        cols.push(col);
      }
    }
  }
    
  for(let row = 0; row &lt; matrix.length; row++){
    for(let col = 0; col &lt; matrix[row].length; col++){
      if(rows.includes(row) || cols.includes(col)){
        matrix[row][col] = 0;
      }
    }
  }
}

For further refinement, rows and cols might/will get multiple times the same value, so to deal with that gracefully you should use Sets for that.