While Passing Array in call Method works well as I am able to iterate it,but
in case of apply it gives an error while iterating the array. (although it only takes array-like object as argument)
var student = {
fname:'vipul',
lname:'jadhav',
fullName:function(){
return (this.fname+' '+this.lname);
}
}
function getMarks(marks){
console.log('USER : '+this.fullName());
console.log('MARKS :')
for(let i of marks){
console.log('marks :'+i);
}
}
var getMarksCall = getMarks.call(student,[99,78,89,90]);
var getMarksApply = getMarks.apply(student,[99,78,89,90]);
It gives an error as
Uncaught TypeError: marks is not iterable
In another case when i changes for loop to
for(let i=0 ;i<marks.length;i++){
console.log('marks :'+marks[i]);
}
then i got to know that marks is only the first value of array.(see image) debugger_screenshot
1.what is the actual difference between the call and apply.. because call also supports the array as argument then what is the need of apply?
2.why the difference between iterating the array in two methods? 3.How to iterate the array in apply?
Could anyone please help me to geeting this ?