wqpcrystal.blogg.se

What is mean in javascript
What is mean in javascript










what is mean in javascript

It's one way jQuery can select an element. That’s why in this case, the global variable name got printed to the console.That's jQuery and the pound sign (#) refers to an element's ID. Whenever a standalone invocation of a function is made, default binding applies and the this variable of the function is set to the global object. Have a look at the call site: myFunction()Īs you can see, it is a standalone invocation of a function. The above piece of code actually prints out “Global Name” rather than undefined as most of you would have expected.

what is mean in javascript

Type 1 – Standalone function invocation – Default BindingĬonsider the following piece of code. The call site of a function is the place where the function is actually invoked. The topic is extensive to be discussed in this post, but you can read about it here.įor the sake of sticking to the topic and for brevity, we’ll focus on only two ways.įirst thing we have to understand is that, the value of this depends on the call site of the function, unless the value of this is explicitly set using call/bind functions. There are four ways in which a this variable can get it’s value. ES5 introduced the bind/call method to set the value of a function’s this regardless of how it’s called, and ES2015 introduced arrow functions whose this is lexically scoped (i.e) it is set to the this value of the enclosing execution context. It can’t be set by assignment during execution, and it may be different each time the function is called. The value of this in most cases, is determined by how a function is called. This is a special variable available inside the context of a function when it is invoked. Let’s begin with a basic understanding of what a this variable actually is and then we’ll see how a this variable gets it’s value. So I did some digging into it and found out why this assignment was a necessity back then and how we can overcome them. that = thisįirst impressions, you could figure out that it had something to do with the value of the variable this being inconsistent, so they had to store in a variable and use it later. When you go through some of the popular JS libraries you might start noticing this peculiar line all over the place.












What is mean in javascript