Javascript interview question | closures in javascript

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

Welcome to comscience simplified. In this week's video, we will look into closures in javascript which is one of the most important javascript interview questions.
We are planning to start out with a concept that is a hot favorite of many interviewers i.e. Scopes & Closures.
Today, we will take this common interview question with the 'for' loop and a variable in the closure scope to analyse the output of the code snippet.
We will look at a work-around solution and then, an efficient, optimized solution to this problem.

Here are some links to our other popular videos:

1. Learn about public-key cryptography

2. maximum substring in a string (Google interview question)

3. How the javascript engine works?

4. Real time median in a stream, another google interview question

5. Understand the Javascript event loop

6. Understand Promises in javascript

7. Git basics you must know

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

It won’t be output at intervals of “1 sec each” since the interval is i * 1000 so 1 sec, 2 sec, 3 sec etc.

tonyohagan
Автор

for (let i=1; i <=5; i++) {
setTimeout (function timer () {
console.log(i);

}, i*1000)
} // Actually the output is 1 2 3 4 5

erasmasngandu