Call, apply & Bind in JavaScript - Front End Interview  Episode 4 - In 20 Minutes

Call, apply & Bind in JavaScript - Front End Interview Episode 4 - In 20 Minutes

Technical Suneja

2 года назад

88,590 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@RaviKumar-hz8cf
@RaviKumar-hz8cf - 13.11.2023 12:47

Tank you Buddy

Ответить
@hemangkoshiyar
@hemangkoshiyar - 17.10.2023 10:21

One thing to consider here is, that if we use the arrow function instead of the es5 function(), then this keyword will point out to a global window object instead of a particular object.

Ответить
@vikrambais5330
@vikrambais5330 - 12.09.2023 12:50

plz also make some frontend projects using react js .. there are very less video just focusiing on frontend projects using react js.. videos to hai par we sab full stack pe focussed hai .. and jab tak ek beginner frontend hi nhi sikh payeha using react js to in sabhi full stack projects ko kaise kar payega..

Ответить
@vikrambais5330
@vikrambais5330 - 12.09.2023 12:40

commenting for better reach

Ответить
@MAJORpiyush
@MAJORpiyush - 10.09.2023 13:40

good video nyc

Ответить
@user-qx8cf5ns3q
@user-qx8cf5ns3q - 29.08.2023 09:34

thank you so much finally clear my doubts in these 3 methods

Ответить
@shahidabbas2932
@shahidabbas2932 - 28.08.2023 17:51

sir event loop in javascript vs event loop in node js iss pa ek details video banawo

Ответить
@user-hk6ip5qe8x
@user-hk6ip5qe8x - 23.08.2023 12:34

It helped me a lot , thanks

Ответить
@tayebkhan2061
@tayebkhan2061 - 21.08.2023 21:04

nice sir
The way you explained call,bind and apply....it's fantastic

Ответить
@user-eo3oc8ef3y
@user-eo3oc8ef3y - 15.08.2023 18:29

Thankyopu so much best explanation and simple explanantion

Ответить
@harishkumarsbd
@harishkumarsbd - 02.08.2023 15:57

superb👍

Ответить
@shreyash8273
@shreyash8273 - 31.07.2023 19:05

Thanks Sir

Ответить
@user-ek6to2wf2u
@user-ek6to2wf2u - 28.07.2023 10:06

In JavaScript, call, apply, and bind are methods that allow you to control the value of the this keyword within a function and also enable you to pass arguments to a function in different ways. These methods are commonly used in object-oriented programming and functional programming paradigms.

Call Method:
The call method is used to call a function and explicitly specify the value of this inside the function. It allows you to pass arguments to the function individually as a comma-separated list.

javascript
Copy code
const person = {
name: "John",
sayHello: function() {
console.log(`Hello, my name is ${this.name}`);
},
};

const anotherPerson = {
name: "Alice",
};

person.sayHello(); // Output: Hello, my name is John
person.sayHello.call(anotherPerson); // Output: Hello, my name is Alice
In the example above, we have an object person with a method sayHello. Using call, we can invoke the sayHello method with a different object anotherPerson to change the value of this inside the method.

Apply Method:
The apply method is similar to the call method, but instead of passing arguments individually, it takes the arguments as an array.

javascript
Copy code
const person = {
name: "John",
sayHello: function(greeting) {
console.log(`${greeting}, my name is ${this.name}`);
},
};

const anotherPerson = {
name: "Alice",
};

person.sayHello("Hi"); // Output: Hi, my name is John
person.sayHello.apply(anotherPerson, ["Hello"]); // Output: Hello, my name is Alice
In this example, we have modified the sayHello method to accept a greeting argument. Using apply, we can pass the arguments in an array to change the value of this inside the method and provide the greeting.

Bind Method:
The bind method is used to create a new function with a specific value for this, which can be used later. Unlike call and apply, the bind method does not immediately invoke the function but returns a new function with the specified this value.

javascript
Copy code
const person = {
name: "John",
sayHello: function() {
console.log(`Hello, my name is ${this.name}`);
},
};

const anotherPerson = {
name: "Alice",
};

const helloFunction = person.sayHello.bind(anotherPerson);
helloFunction(); // Output: Hello, my name is Alice
In this example, we use bind to create a new function helloFunction with the value of this set to anotherPerson. When we call helloFunction(), it logs the message with the name from anotherPerson.

Choosing Between Call, Apply, and Bind:
The choice between call, apply, and bind depends on your specific use case. Use call or apply when you want to immediately invoke a function with a specific this value and pass arguments individually or as an array, respectively. Use bind when you want to create a new function with a preset this value to be called later.

In summary, call, apply, and bind are powerful methods in JavaScript that allow you to control the value of this inside a function and provide flexibility in passing arguments. Understanding how to use these methods can enhance your code's readability and enable you to create more robust and reusable functions.

Ответить
@nileshsable3872
@nileshsable3872 - 15.07.2023 11:51

its awesome video all douts clear sir thank you

Ответить
@sunnyrauniyar6769
@sunnyrauniyar6769 - 11.07.2023 22:00

Great simple explanantion again, this video could have been a little shorter or you could add some use-case or necessary situation usecase at the end of video. Thanks again

Ответить
@NikhilKumar-ec9lf
@NikhilKumar-ec9lf - 03.07.2023 22:50

👍👍👍👍

Ответить
@yashpawar7881
@yashpawar7881 - 21.06.2023 06:42

Why can't we use below method instead of call or apply?

function printDetails(obj) {
console.log(obj.name)
}

printDetails(userDetails);
printDetails(userDetails2);

Ответить
@shwetajaiswal1263
@shwetajaiswal1263 - 11.06.2023 12:45

U are great

Ответить
@MajidKhan-lw4ny
@MajidKhan-lw4ny - 06.06.2023 17:04

Episode🤣🤣🤣🤣🤣

Ответить
@piyush93688
@piyush93688 - 14.05.2023 16:16

this ko aise bhi samjha ja sakta hai ki wo apne parent object ko point karta hai. agar wo kisi object ke andar nahi hai to global object ko point karta hai.

Ответить
@niteshsen690
@niteshsen690 - 05.05.2023 19:43

Very well explained ❤

Ответить
@siddharthabiswal275
@siddharthabiswal275 - 04.05.2023 18:58

LOVELY!

Ответить
@prsanjeetpanwar3689
@prsanjeetpanwar3689 - 03.05.2023 14:34

sir please raat ko mat padaya karo hame bhi nind aati hi

Ответить
@amansingh8697
@amansingh8697 - 02.05.2023 12:48

Very helpful video thank you sir❤❤

Ответить
@avinashpawar2236
@avinashpawar2236 - 01.05.2023 16:28

Thanks alot sir 🤗 amazing video

Ответить
@rohanmainali9040
@rohanmainali9040 - 28.04.2023 15:10

Please learn these concepts because today in my mid-level react interview I got these questions.

Ответить
@prathmeshrupnur2416
@prathmeshrupnur2416 - 25.04.2023 21:03

nice video every point discussed in video was clear to me
sir ,i request u to make a playlist on javascript for beginners to advance.

Ответить
@sandeepsunny8467
@sandeepsunny8467 - 18.04.2023 15:56

nice explanation with simple real examples....)

Ответить
@rishabhprakash
@rishabhprakash - 17.04.2023 08:04

thanks man !

Ответить
@AnoopSeth
@AnoopSeth - 12.04.2023 15:24

Video acchi hai bas 2 minutes starting me skip maar do

Ответить
@shaansharma2504
@shaansharma2504 - 10.04.2023 14:01

we support you :)

Ответить
@indpriderdx5174
@indpriderdx5174 - 12.03.2023 15:25

greate tutorial hats of to you sunejaji .. nice-one

Ответить
@sparsh-0384
@sparsh-0384 - 12.03.2023 10:58

Well explained 👍

Ответить
@hitanshpatel9548
@hitanshpatel9548 - 18.02.2023 18:45

Your explanation is really very good and understandable.

Ответить
@sankethtj
@sankethtj - 12.02.2023 17:17

Very Well Explained. Thank you very much..

Ответить
@coding_is_my_passion
@coding_is_my_passion - 08.02.2023 13:32

bind means copy of function to always get the same value Ajay Suneja Delhi and India in this video Call, apply & Bind in JavaScript - Front End Interview 🔥 Episode 4 - In 20 Minutes

Ответить
@bhumikasingh4419
@bhumikasingh4419 - 08.01.2023 16:53

Very well explained with examples! Thank you!

Ответить
@RahulChauhan-lm8mk
@RahulChauhan-lm8mk - 05.01.2023 21:49

Very good video. Immpressive.

Ответить
@Yash-ry5wj
@Yash-ry5wj - 04.01.2023 09:03

Thanx Bhaiya ❤️, Understood all.

Ответить
@unseenjoda9899
@unseenjoda9899 - 30.12.2022 10:44

Explained Nicely... Jab hume pata hi nahin hai problem kahan hai... Solution ko kaise use karen... Great sir

Ответить
@YashDEVELOPER12
@YashDEVELOPER12 - 23.12.2022 10:53

And brother plz make video on what are the important topics to learn before starting react js ...

Ответить
@YashDEVELOPER12
@YashDEVELOPER12 - 23.12.2022 10:51

One important use of bind function is :
When we used a function as callback like setTimeout() , there is chance that method loose reference of object .
So to tightly bind the method with object we can use bind method.

Apart of this.. thanks alot brother for explaining call and apply function very well..

Ответить
@jesussheepakash9289
@jesussheepakash9289 - 18.12.2022 16:12

Thank you bhaiya

Ответить
@sayyedmoin3743
@sayyedmoin3743 - 18.12.2022 14:44

Array interview question and answers

Ответить
@jaikrishnaverma7909
@jaikrishnaverma7909 - 08.12.2022 11:16

sir ek suggestion h... try kra kriye thoda time kam lene ka.... agar koi aur wahi topic kafi kam time me explain kr de ra ... to apko koi kyu yad rkehga ......... avi space banaiye content solid rakhkr..aur bad me watchtime badhaiyega

Ответить
@pankajsuryavanshi8332
@pankajsuryavanshi8332 - 17.11.2022 09:44

Continue this series.....

Ответить
@waytolivelife
@waytolivelife - 05.11.2022 16:37

Live projects me kya use h ?

Ответить
@daminiraj4846
@daminiraj4846 - 20.10.2022 06:58

Pls make more videos on advanced javascript

Ответить