Advance JavaScript for Beginners

Advance JavaScript for Beginners






















                                   Click here to join

Advance JavaScript for Beginners

JavaScript now let's dive a little bit deeper on advanced techniques for this we're just going to use the council and chrome now we've already talked about functions for instance have a variable say hello so let's make it equal to and this is how you define a function in es6 it looks pretty funky but it's pretty much the works let me clear this now the default namespace is the window so if I say window you'll see it returns this object and it has a bunch of different stuff in it so if I declare a variable and call it my name it's attached to the window object window my name and when you're creating large JavaScript applications outside name is only available inside this function and that's pretty much how scoping works so it's important to keep everything in its own scope that way you don't get the collision of variable names keeping everything in its own namespace which brings us to an iffy this stands for immediately invoked function expression so let me just open up visual studio real quick I know I changed editors I was using atom in the last time this time I'm using visual studio I just kind of like switching itI because I can't instantiate it twice another thing is it's going to carry this value so say for instance here I wanted to just define the variable name and then say hey if name doesn't have if name doesn't have a value then I want to do this well name would name would have a value would have that with all these variable names not in their own scope so by using an immediately invoked function expression it allows you to create a scope to keep your application in and how you do that it's just like this now when this javascript file is loaded it's gonna immediately run whatever is inside this and i can create a variable thing that I want you to take away from this is whenever you're creating a JavaScript application you should wrap your whole JavaScript application in one of these statements and what global namespace the global namespace being the window but that also has to do with each one of these scopes too so you could have that same issue where I defined the name here and then I try to redefine name down here so just start paying attention to what scope you're defining your variables in next let's talk about the this keyword now I wrote this little note here this is equal to window because in this global namespace this is equal to the window because window is the global object but this refers to whatever object it's contained in so say for instance bar my object and I create an object and I add a key value pair on it and let's add a function to it now I can return this dot name let's concatenate hello to it now this refers to the object that's contained car.
Share To:
Next
This is the most recent post.
Previous
Older Post

CourseMajor

Post A Comment:

0 comments so far,add yours