Sign in

apply() Method in JavaScript

“ Let’s understand apply( ) method in JavaScript ”

image of javascript

To begin with there is no major difference between call() and apply() , in call() the arguments are passed separately , in apply() the arguments are passed in array

go through about call() method here

const obj1={
f_name : "xyz",
l_name : "zyx",
print : function(title){
console.log(` ${title} . first Name : ${ this.f_name } ,
last Name : ${this.l_name} `)
}
}
obj1.print("Mr"); // this method of passing arguments is know
const obj2={
f_name : "efg",
l_name : "gfe",
}
obj1.print.apply(obj2,["Mr"])