![]() ![]() In simple words - Closures are functions that return another function, and the inner function has access to the outer variables function (You can read more here). FYI, we can fix this behavior by add "use strict". When we do assignments without declarations in JavaSacript ( a=2), the compiler will save the variable in the global scope. According to the logic we talked about in the previous question, the variables should be in local scope, But, if you pay attention, the variables didn't declare (without var, let, const). This is why JavaScript is a unique language. If you said a is not defined, you have healthy thinking, but the answer is 2. it's a different place in memory (even if they have the same name). The var a = 2 declared inside the function and saved in local memory. The var a = 1 declared out of the function and saved in global memory. In JavaScript, there are two types of scopes: Global Scope and Local Scope, variables declared within a JavaScript function become local, and variables declared outside of the function become global. I think the answer is pretty straightforward. Notice 3!: For each question think what will be the output.Įnter fullscreen mode Exit fullscreen mode Notice 2!: If you run the questions on the console, remember that some of the variables are repeating themselves, so do refresh from question to question. Notice 1!: To each question, there is an answer with an explanation (link below each item). ![]() So are you ready to get your mind blow away (from JavaScript question)? There are many other resources to learn from. Of course, this is only some of the resources on the subject. He explains how JavaScript works "Behind the scenes" (how the event loop works). What the heck is the event loop anyway? | Philip Roberts | JSConf EU - One of the most famous JavaScript videos recently. ![]() What Makes Javascript Weird.and AWESOME - I found this Youtube playlist, In my opinion, the explanations are very understandable, and he shows visual code examples.That you can learn a lot about JavaScript foundations. 70 JavaScript Interview Questions - Excellent article.In this article, I'll show you mind-boggling questions (for me, it was mind-boggling, I hope for you as well) that we can learn some of the concepts behind these questions.īefore we start, I want to mention some of the resources I used for writing this article, and I highly recommend you to use them as well: As part of my journey to become a better JavaScript programmer, I need to dive deep into JavaScript foundations. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |