Learn Closures In 13 Minutes

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

Closures are one of the core features of JavaScript that every developer needs to understand. You not only need to know what they are and how they work, but you also need to have a deep understanding of various niche behaviors of closures since many jobs will ask you complex interview questions on closures. In this video I will cover what closures are, how they work, and multiple example interview questions so you can be prepared for whatever gets thrown at you.

📚 Materials/References:

🌎 Find Me Here:

⏱️ Timestamps:

00:00 - Introduction
00:50 - What Is A Closure
05:40 - Why Are Closures Important
08:36 - Closure Interview Questions

#Closures #WDS #JavaScript
Рекомендации по теме
Комментарии
Автор

I just gave my interview and in this interview they asked me about closures. which ofcourse i have no idea. I have used it but no idea what is called. and i open my youtube and boom you are there. really like the simple explaination.

usmanquickcode
Автор

React vue and angular use closures all the time, all functional components are closures

xzex
Автор

Just incredible video as always. Somehow you always get to the absolute core of a concept and then demonstrate it beautifully

joesharp
Автор

I use one type closure all the time, combined with promises, when I have to execute a function on an array of data asynchronously, all you have to do is return a promise with a function, inside create a couter at 0, create the function thats going to process an entry, before return, incremente the counter, and excecute the inner function again, when its done, resolve the promise.

RaimundoAraujoCorrea
Автор

Thanks a lot, I know and remember how closure works in javascript, but I never knew about something tricks.

PavloBozhok
Автор

That for loop let var closure interview question is just brutal

captkalik
Автор

dude be selling 10 other videos within 1 video

Автор

I had doubts for this last example, so I asked gpt to explain it to me deeply. It errored the first few times but at last gave the correct answer which claude also verified.

Yes, for each iteration of the loop, a new scope is created, and within that scope, a new binding for the variable i is created. Here’s a detailed breakdown:

First Iteration (i = 0):

A new scope is created.
A new binding for i is created and initialized to 0.
The setTimeout callback captures this binding, so it logs 0.
Second Iteration (i = 1):

A new scope is created.
A new binding for i is created and initialized to 1.
The setTimeout callback captures this binding, so it logs 1.
Third Iteration (i = 2):

A new scope is created.
A new binding for i is created and initialized to 2.
The setTimeout callback captures this binding, so it logs 2.
In each iteration, the let declaration ensures that i is re-declared and re-initialized within the new scope. This results in three separate bindings for i, each one unique to its iteration.

himalayagupta
Автор

So, if I can sum up and get confirmation: a closure is where an outer function or scope is not garbage collected because there is an inner function that relies on the outer function or scope's variables... is this correct?

tommysmith
Автор

Printing 3 times 3 has more to do with the event loop than closures

plamenyordanov
Автор

Hello Kayal, In your second example for closuers "function elementCreator(element)", if we directly return instead returning a function then what difference will it make, I think direct return will be better, what you suggest.

saurabhshrivastava
Автор

This is the best explanation of closures I've seen (including your own previous explanations).

lesalmin
Автор

it would be good if you cover conditional scope or conditional closures

crakyanime
Автор

Great video as usual. But Kyle, your 1x Playback speed feels like 1.25x bro. 🙂
Interviewers also ask that how you will print 0, 1, 2 when using var i=0; . We have to use the concept of closure here.

manpreetjord
Автор

Excellent and really clear approch and explantion

karimkrimou
Автор

What is the purpose of returning function which returns element and not returning element with the first function?

mcRidersEvolution
Автор

I think the explanation for var, let with for loop is a bit wrong. 🤔

consoledoterror
Автор

Can you make a video talking about message queue?

QuanTran-wtyt
Автор

Thank you for this video and the job you do, but what is a JavaScript Developer? The only thing i could find is "JS developer" - in react, angular, vue and stuff
Is there atually a job for JS developer in JS?

alexandraweather
Автор

Dear, could you please explain what is JavaScript reference memory?

iftekharhaidar