[Solved] Why print ‘NaN’ value in javascript? [closed]


Replace , with = it will also work fine! Initialize variable

var scores = {
  val1: 90,
  val2: 100,
  val3: 98,
  val4: 95
}

function calcAverage() {
  var sum = size = 0;
  for (var key in this) {
    sum += this[key];
    size++;
  }
  return sum / size;
}
console.log(calcAverage.apply(scores));

5

solved Why print ‘NaN’ value in javascript? [closed]