Javascript Interview Questions ( Closures ) - Lexical Scope, Output based Questions, Polyfills

preview_player
Показать описание
#Javascript #FrontendInterview #AccioJob

Javascript Interview Questions on closures will be discussed in this video including topics like Lexical Scope, Scope Chain, Output based Questions, Once and Memoize Polyfills, etc.

AccioJob is an IIT Delhi alumni-led startup that runs a 6 month Pay after Placement Full Stack Web Dev Training. Students are trained on Data Structures and Algorithms, Full Stack Web Development and backend web development. Students get placed above 5 LPA. AccioJob students are working at Amazon, Walmart, VISA, BharatPe, Paytm, ThoughtWorks and 190+ more companies.

Key Highlights of the program:
- ZERO fees till Placement above 5 LPA in Software Development
- Average CTC: 8.3 LPA; Highest CTC: 41LPA
- Dedicated placement team & Interview preparation
- Industry-relevant Projects, Mock Interviews, Resume & Portfolio building

🟦 Follow me on Twitter and u will clear your interview 🤓 -

⭐ Support the channel and learn from me One on One -

📖 Blog for this video -

🔗 Var, Let and Const Interview Video -

🔗 Functions Interview Video -

🔗 JavaScript Interview Series -

🔗 Cars24 Interview Experience -

🔗 Unacademy Interview Experience -

🔗 MERN Stack Tutorial with Redux -

🔗 React Beginner's Project Tutorials -

-------------------------------------------------------------------------

00:00 Intro
00:33 What is Lexical Scope?
02:22 A great oppertunity for you!
03:38 Lexical Scope - Interview Question
04:52 What is Closure?
05:43 Example of Closures
06:56 Why Closure?
08:19 Closure Scope Chain
11:12 Question 1 - What will it print ?
13:09 Question 2 - Write a function for this
15:28 Question 3 - Time Optimisation with Closures
18:07 Question 4 - setTimeout + block scope with Closures
23:07 Question 5 - Create a private counter
25:48 Question 6 - What is Module Pattern?
27:31 Question 7 - Make this run only once
30:14 Question 8 - Once Polyfill Implementation
34:02 Question 9 - Memoise/Caching Implementation
39:37 Question 10 - Closure vs Scope
40:22 Written Article for this video

-------------------------------------------------------------------------

Special Thanks to our members -
Trevor M
Srinivas Ayyagari
Рекомендации по теме
Комментарии
Автор

Great content, i recently gave a interview in cleartrip they asked this 4 question 1) write polyfill for promise 2)deep comparison of object 3) polyfill for call, apply, bind 4) polyfill for map, reduce, filter, forEach. It's help me and others if you can cover this questions

hmehta
Автор

Bro thanks for sharing such knowledge in your videos but at the same time you need to make sure you are doing it right as so many people are watching these content, here in memoise polyfill your code is mistaken Json.stringyfy(...args) will not return us "500, 500" in res object instead it will just jive us the first value of the array as we are not iterating the args array therefore even if we pass (500, 500) and (500, 600) as args we will get the same result and in the second function call res will mark the args as present in the object already, so to avoid we can do argsCache = args.join(", ") then it will store in the res object as explained in the video

by the way thanks for your content.
happy coding to all

sunnykalita
Автор

These series are true GOLD, if possible keep on adding.

ankitasingh
Автор

Through middle of this session and I already feel enlightened. Thank you so much :D

DS-zrgv
Автор

I never found something like this on youtube
Gr8 job man

ShivamSingh-ctix
Автор

Please do asynchronous/ concurrency javascript interview questions. They are the toughest. Thanks for this!

JudoboyAlex
Автор

Worthy 40 minutes.
Keep sharing this kind of videos :-)

AmanSingh-qrld
Автор

your Interview series is amazing 🔥 and worth watching 🚀

abhishekvishwakarma
Автор

Videos are good. But one suggesting instead of asking us to refer ur previous video just explain the functionality in one line
& it will be much much helpful...

AnandKumar-dcbf
Автор

For those of you wondering how to fix the var scope issue with closure.

const c = () => {
for(var i =0; i < 3; i++){
((i) =>{
setTimeout(() => {
console.log(i);
}, 1000);
})(i);
}
}

c();

emilyaung
Автор

use IIFE to make it work with var
for (var id = 1; id <= 3; id++) {
// Using an immediately-invoked function expression (IIFE) to create a new scope for each iteration.
// This helps avoid the closure issue with setTimeout.
(function (id) {
setTimeout(function () {
console.log('seconds: ' + id);
}, id * 1000);
})(id);
}

iamankitdadhich
Автор

Thankyou for this knowledge packed closures' video Pyiush. It is the most detailed video I found on Youtube and it covers all the important questons. Please make more of such content 🖖👍👌

anubhapant
Автор

Hi RoadsideCoder, great lessons, your explanations are very clear, thank you for all this work!

I still have a question about "Question 8 - Once Polyfill Implementation"
You pass a "context" argument and then apply it to the function, but I don't quite understand in which cases it would be useful?
In your example "this, arguments" are applied, and everything would work even if we delete "context" from the code.
When is it useful to pass a "context" and what kind of data is expected for this argument?

hellisayhello
Автор

"At 22:51, wouldn't creating the inner function inside the loop lead to a new function being created in memory every time? I think a better approach would be to define the function outside the loop, so it's created only once. This way, the function can be reused, which is more efficient."

function print(num) {
setTimeout(()=>{
console.log(num)
}, num * 1000)
}

for(var i = 0;i<3;i++) {
print(i)
}

mjzbjtx
Автор

Hey Piyush that Time Optimisation part was something new that I learnt today 16:20. Can you explain the the exact reason what closures did such that it took less time to execute the function

saikumargatla
Автор

This guy is great - good content and personality to

rxtechandtrading
Автор

Great content on closures keep making more and also make on React challenges which are asked in interviews

AARP
Автор

At 34:00, The apply method takes the array of arguments but you are passing it separately just like we pass in the call method, how does it work?

mjzbjtx
Автор

Nice video but you did not clearly explain why the time got reduced in the time optimization :(
I'm assuming it is meoizing the values underthe hood!

AjithKumarsham
Автор

Your explanation is very clear and the content is very useful. Can you make series for MERN interview questions

abhishekchaurasia_