Implement a custom forEach in javascript | JS Interviews

preview_player
Показать описание
Javascript interview series

Sara code yaha milta h

Discord pe yaha paaye jaate h:
""/discord
Instagram pe yaha paaye jaate h:
Рекомендации по теме
Комментарии
Автор

Small correction. It’s actually this.hasOwnProperty(i)

I missed it while explaining.

chaiaurcode
Автор

Second implementation was unexpected, thank you sir for making it on more advanced level.

deepeshji
Автор

you are changing the way we code or the way we learn things
great efforts by you
we appreciate your effort
always be happy sir
ap hamesha salamat rahay

tech_channel
Автор

This video will compel you to think about how things work internally. Undoubtedly, this gives a better understanding. Thank you. I ended up creating custom map, filter, reduce methods :)

madhulikablore
Автор

This JavaScript code is extending the built-in Array.prototype with a new method called forEachTwo. This custom forEachTwo method is designed to iterate over an array and apply a provided callback function to each element. Let's break down the code step by step:

*Extending Array Prototype:*
The code begins by defining a new method called forEachTwo on the Array.prototype. This means that once this code is executed, all arrays in the JavaScript environment will have access to the forEachTwo method.

*Function Parameters:*
The forEachTwo method takes two parameters:

*callback:* This is the function that will be called for each element in the array.
thiscontext: An optional parameter that represents the context in which the callback function should be executed.

*Callback Function Check:*
The code starts by checking if the provided callback is a function. If it's not a function, an error is thrown with the message "Not a function."

*Getting Array Length:*
The length of the array on which the method is called is stored in the length variable.

*Looping through Array Elements:*
The code uses a while loop to iterate over the array's elements. The loop continues as long as the index i is less than the array's length.

*Checking Property Ownership:*
Inside the loop, there's a condition if (this.hasOwnProperty). However, this condition is incomplete and should actually be checking if the array instance itself (this) has a property corresponding to the current index i. The correct condition should be if (this.hasOwnProperty(i)).

*Executing the Callback:*
If the array has the property at the current index, the callback function is executed using the call method. The call method allows you to invoke a function in a specific context (thiscontext) and pass arguments to it. The callback is invoked with three arguments:

The current array element (this[i])
The index of the current element (i)
The entire array (this)
Incrementing the Index:
After executing the callback (if applicable), the index i is incremented by one.

The purpose of this code is to create a custom version of the forEach method for arrays, which can handle a specified execution context for the callback function. However, there is a minor issue in the code related to the if (this.hasOwnProperty) condition that needs to be corrected for the code to work as intended.

ck
Автор

loved it hitesh sir ❤aur videos chiye jaldi jaldi

mtg_
Автор

in depth explanation king
big respect KIng

tech_channel
Автор

Sir, please try to upload next react video soon..🙏

abhishekkashyap
Автор

Sir You're making a huge impact . Universe of JavaScript. Thank You Sir

husnainali
Автор

Great series sir, learning a lot.
Concept pura refresh and ache se clear ho jata hai.

akashthoriya
Автор

Started loving your content and loving your way of talking even more

mostlyinfinite
Автор

what a video.
Please make more such sensible and thinkable videos

NeerajKumar-klxf
Автор

🚀Inside the loop, there's a condition if (this.hasOwnProperty). However, this condition is incomplete and should actually be checking if the array instance itself (this) has a property corresponding to the current index i. The correct condition should be if (this.hasOwnProperty(i)).

ck
Автор

I wanted to express my heartfelt appreciation for your exceptional dedication in providing interview-focused content that delves deep into JavaScript concepts. Your effort in preparing us for real-world challenges is truly commendable, and I'm incredibly grateful for the valuable insights you've imparted to help us succeed in our future endeavors.

tech_channel
Автор

mind blowing implementation of call with context

snehasish-bhuin
Автор

Sir just a small request,

aap batate ho ki, interview me question pucha karo,
question puchne se interview intrective rahta hai, interview acha jata hai,

Can you please video on that?
Kaise technical discussion karna hai?
kaise question kar sakte hai?
question karne ke time par kya kya chize dhyan me rakhni chahiye?

Aap ki communication skills badhiya hai sirji 🔥

akashthoriya
Автор

wow Sir amazing❤. I just learn portotype from this video alone.

vijayroy
Автор

please continue this series
this series are very helpful for inteview

dynamiczonex
Автор

Thanks for the Interview series Sir, Much gratitude

Jonathan.
Автор

sir ek requeest hay ap sy
kindly JAMSTACK vs MERNSTACK py ek video bana dijiye

tech_channel