Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Understanding JavaScript closure and where it can be used

ClosureThe official definition of closure is: an expression (usually a function) that has many variables and is bound to an environment that includes those variables.In JavaScript, closure refers to the ability of a function to access the lexical scope in which it was defined, even after the function has been executed and left that scope. This ability is due to the fact that when a function is created, it generates a closure that includes a reference to the definition environment of the current function, allowing the function to continue to access those variables within that environment.Below ...

1,190 0       CLOSURE JAVASCRIPT USAGE


  JavaScript interview questions

This post will cover the JavaScript questions I have encountered and have seen during my programming career. They will mainly focus on vanilla JavaScript though there are lots of excellent frameworks out there and many people are using them in their daily work.this keywordthis keyword is an very important but easy to confuse concept in JavaScript since it is always referring to the calling object of the function.1. What will be the output of below code snippet?function User(name) { this.name = name; this.display = function(){ console.log(this.name); }}var user = new User("javas...

9,073 0       JAVASCRIPT ALGORITHM THIS CLOSURE


  JavaScript: Private variables

The first thing you often hear when talking about JavaScript is often “JavaScript doesn’t have visibility modifiers, hence it doesn’t support private variables”. This is only valid for 50%, because JavaScript indeed doesn’t have visibility modifiers (public, private, friend) but it has closures and function scopes. With these tools we can make variables private. Let’s take the following function:var names = ["Kenneth", "John", "Marc", "Robert"];var lookup = function (index) { return names[index];}alert(lookup(0));As you can see the variable “names&r...

4,484 3       JAVASCRIPT PRIVATE VARIABLE CLOSURE