hey so if we have clicked on this video chances are that maybe you've always wanted to learn node.js and why wouldn't you it is one of the most popular server-side environment that exists out there so we at Kayla are bringing you a very extensive and a very Advanced node.js course which will take you from scratch to Advanced I'm working as a developer Advocate with scalar and I'll be taking you throughout the course where will understand every what when and house of node.js so without any further Ado let's get started so before diving into node.js and understanding all the ins and outs of it we first need to understand JavaScript we first need to learn the basics of JavaScript because obviously node.js is a runtime environment of JavaScript uh you can just say that that road node.js will actually allow you to run your JavaScript code on your machine and that is what it is called runtime environment of JavaScript so node.js is basically built upon C plus plus but it supports the language JavaScript we write a code in JavaScript all right so we need to understand the basics of JavaScript first so any programming language right wherever you're learning any programming language there are some basic stuff that you need to know like declaring variables how can you declare variables in JavaScript how can we initialize arrays how can we initialize objects right how can we initialize how can we create functions and there is one thing in JavaScript that is known as scoping so uh different variables uh basically there are three type of keywords in JavaScript like who are encons they all have different type of scoping so we'll understand that also there are two types of scoping block scoping and function scope let me write that again so before diving deep into node.js we'll understand the basics of JavaScript and we'll install node.js first we'll install node.js first we'll see how we can install node.js we'll see how you can run your first JavaScript program in your local machine and we'll also see how does your browser run smooth uh JavaScript so basically there are two environments in which you can actually run your JavaScript code first one is browser JavaScript was by default built for browsers only but then the node.js came and now with the help of node.js you can actually run your JavaScript code on your local machine as well right so let's just start with the prerequisites that we need that is the JavaScript Basics so first of all what we will do will actually go and will install node.j so we'll see how we can install node.js for your Windows machine we'll see how I can install node.js for your Mac machine and of course Linux machine so let's just go and let's just try and get started so before installing node.js and getting started with node.js getting started and working with node.js uh let us see that how does browser uh works with JavaScript right so uh here I am at my browser right and I'll just right click here and I'll just say inspect and here you can see an option that is console you can just go to Horizon and you can just write anything this should be JavaScript code but so there is a method that actually helps you block something I mean that actually helps you bring something on the console this area is known as the console so the method is console.log so what I'll write is console DOT log and here you can say anything right I will say hello inside a string and here what I'll do I'll just press enter so now you can see Hello will get printed over here okay and also I can declare any variable I will say uh let x equal to 2 and we can just go and we can again console.log the value of x and you will get two here right so in this way browser will actually help JavaScript to run inside it right uh so uh there are basically uh the concept of JavaScript engines that is helping uh doing all this stuff right so uh but do you think that writing code in this console will help us you know all right so to write JavaScript code what we'll be using is we'll be using an IDE so I'll be using vs code for that you can choose any ID that you prefer all right so just let me quickly uh start with vs code so here I've created a pulled up node Scala inside this will uh we'll be covering everything we'll be writing on the code so uh what I will do is I'll just create a folder here and I'll just name this folder environment all right so the first environment that we'll discuss is the browser as you saw that we can run JavaScript code inside the browser but what if we need an ID what if we need to write code and then link it to the browser and then we'll see everything uh working there right so first of all what you need to do is you need to create an HTML file and HTML file so let me just name this for now as index dot HTML right and then what I will do is I'll create a JS file over here so let me just say demo dot Js right now in this index.html if you are not familiar with the statement I'll just ask you to go through uh you will just need a hour or so to get familiar with HTML right so I'll not be teaching HTML here because this is a node course so uh I'll just take and I'll just write here HTML right so this is basically the boilerplate code that we write beside this what we can do is we can link our JavaScript so just to uh make you a little familiar with it HTML what does html does is HTML parses everything in your browser right whatever you will write here it will go into your browser's page right uh which you have linked with it so basically what we'll do here is we'll just take a link tag we'll just take a script tag now let's just say script then I'll say script and we'll just close this and inside this script I'll just pass my source attribute as demo.js which is this file which is my this file and inside this demo.js what I'll write I'll just say console.log as we were doing before let's say hello from the browser so what will happen over here is this index.html this index.html basically link this JavaScript file to this specific browser page that is linked to this index.html so let's just open this with live server so I'll just open this fertilizer and you can see this is a Mt HTML page because of course we haven't written any element there is no element that we have written over it right but notice something we just go to inspect and we'll open the console tab you can see there is a message here that is Hello from the browser right and what is that message this is the same message that we have passed in the demo.js file all right so this is one way of writing JavaScript code and this was the only way before node.js for writing JavaScript code because before node.js JavaScript was only made for browser JavaScript used to work with browsers only but now what we'll discuss now we will discuss node shares so let's just go and let's just start with node yes and let's just first install it right so what we'll do is we'll just go to Chrome and we'll come here and we'll just type node.js so uh whenever you will go to Google and you will type node.js this is the first link that you will get which is basically node.js.org I'll print down this link in the description if you want right so you can just go to this link and you will see here that this is the home page of node.js so what you have to do is uh whatever is your system specification if you're on a Mac if you're on a Windows or anything but there is an option you will get options here to download or you can just go into a long term support schedule and you will find in the downloads right in the download tab you can find every version of notice that that is available for you to download according to your system specification right there is Windows installer there is a Mac OS installer and that's it that's it so let's start with as I am on a Windows machine right now so I'll just go and I'll uh uh just download this long term support version or you can actually install the current version so current version is basically the latest release of node.js so maybe it can have some bug or something like that but the long term support version is always useful for you so you can just get started with long term functions so I'll just go and I'll just click on this so you will see that a file is down a file has started downloading here I'll just wait for it to download and now I can open this let me just open this okay so this is the setup wizard of node.js right so the setup widget will install node this on your computer right this giving some messages you can accept the agreement then you can do next then yes I will install it here uh you don't have to do anything here right you just need to click on next button then you do not need to install this uh chocolatey uh for now uh it will just uh make your file size more bulkier so what you can do is you can just untick this box and you can just start with node.js so we'll see next and you can just say install so uh this Setup Wizard will start installing node.js on your system so let's just wait for it a little while and it's here we go so we have successfully installed node.js on the system right and now to check that if you have installed node.js on your system or not you can just go to your command prompt so let me just quickly go to my command prompt and you can just go here and you can type node so as I have typed node you can see that welcome to node.js version 16.15.1 right and you can also type something here like if I say console log or if I say uh uh let's just say let x equal to two right let y equal to 3 and what I will do is I'll just say console.log X Plus y so it will basically print 5 right you don't have to worry about this undefined right now I'll tell you later why this undefined is coming so just ignore it for now you can just see that the code is working we can write a code here we can do any calculation and stuff like that over here only so this will basically show you that node.js is actually installed in a system right so uh of course we cannot write our code here so what we'll do is we'll just again go back to our IDE so you can come back to your IDE and where we were discussing the about the environment so first environment that we discussed is the browser environment now we'll go to node.js so I'll just create a new file over here I've got a folder a file and I'll just say uh node.js just for the name right no.js and inside here I can say console.log hello from node and what we'll have to do is we'll have to run this file now in our local machine now we are allowed now node.js is allowing us to actually run this file on the local machine first what was happening we were only allowed to run JavaScript code over our browse as you saw but now because of node.js we are allowed to run this file in our local machine so let us start with we will just go to open an integrated terminal so that we can get the correct path where our file is and we'll just go here let me just clear this yeah and now to run a node.js file to run a node.js file what command you have to type here so you'll just type node and you will type the file's name the file's name is also node.js let's say node.js L is present so what you can do so what you'll see is you will see hello from node so basically now what you are doing is you're running this code on your local machine and that is what is node.js is required for it will actually allow you to interact with your local machine with the help of JavaScript right so these are the two environments uh that allows JavaScript to run now let's just see the basics of JavaScript and how we can get started with JavaScript we'll be using node only to understand everything we'll be using node only to run every program because uh going into browser and coming back that doesn't make any sense all right so let's just start so we have discussed the two environment in which we can run JavaScript and now what we can do is we can create a new folder here with the name of JS Basics our JS fundamentals we will discuss all the fundamentals of JavaScript so first of all as we have seen we we have seen the First Fundamental the first basic point of JavaScript that how you can print something on your console how you can print something from your program right so ljs fundamentals we'll be starting with declaring variables so first of all I'll just say this as one appointment I'll just say that one underscore variables.js and now let's start by creating some variables and see what are variables and how you can Define variables inside of JavaScript all right let's start so there are basically three it's by which you can initialize a variable in JavaScript now what is a variable of course whenever you're writing a program whenever you are writing a program what do you need what do you need you need to store values you need to store values for future use we need to store values for future use and this is where variables come into picture so what you can do is you can actually create some variables like just suppose I'll say this is a variable a and inside this variable here what I can do is I can store any value right I I can store 20 inside this variable B I can store a hello string right there I can say variable C I can say scalar is awesome and I can also create one more variable where I can set true or false right so uh these so this is now you can create variables inside JavaScript but have you noticed one thing here and never I am never setting any type for these variables if you are coming from the languages like Java or C plus plus or you know this statically type language for example so these languages these languages they actually have this compulsion they actually have this compulsion that you'll have to always Define a type by a variable you'll always have to define a type a variable like in Java if you are actually initializing an integer value right so what you'll have to do is you will write int a and then you can initialize the value like that so yeah basically you are defining the type of this variable but here what you can see is I've just wrote and I'm never initializing or I'm never setting any type over here right so uh I'm talking about this in a very vague manner but let's just go and write some code and see how is this working right so what I'll do is first of all I'll declare I'll discuss the bad word so uh before es6 before let it go there was only one keyword by which you you are allowed to declare variables but there were some problems with or we'll come to that later so uh right now what can we do is we can just say where a and we can set this to 2. we can come now and we can say where B and we can set this to a string scalar is also right and to print this variable what we can do is we can just console.log a and became them sole.com right and let's just go and let's just run this code and see what does this prints so I'll just say node variables dot JS we'll run this code and you can see it prints too and it also prints scalar is awesome it is finding the variable a and it's printing the variable b as well but notice something we did not Define any type for this variable we did not Define any type of this variable and this is what it's the dynamic nature of JavaScript foreign not only this but what you can also do is that you can re-initialize this variable you can redeclare this variable you can reassign these variables right so let me just go and let me just uh do this I'll say where a equal to I'll say 30. right so in other programming languages this thing isn't allowed you are not allowed to redeclare a variable but in JavaScript you are you can also reassign this variable right so first what you have done is you have assigned this a with a number then you redeclared this a with a number you can also do this you can also reassign redeclare this variable with a string and JavaScript will allow that JavaScript will allow that and you can also reassign this variable with a with a different data type value like I I just reassigned this with true this is also right so this is basically what is the dynamic nature of the JavaScript right you can reassign you can re-declare you can do anything with your variables that you put so if I just go into uh vs code if I just go to terminal and run into then run this program again so now you can see it's printing through as we have reassigned the value of a to True right and then it is findings here is awesome because the B variable consists of this value in different programming languages you are not allowed to do this but in JavaScript you are so basically the JavaScript is known as dynamic in nature because of this Behavior Dynamic dynamically typed language we call the script that as a dynamically type language all right so this was it this was the first thing that we need to discuss now so we basically learned how to declare variables in JavaScript with the wire keyword but there are two more keywords that are Latin const so if we had this pair keyword and if there is no need to specify any data type in JavaScript then why do we need more than one keyword that is the question right so there are a lot of problems with that there are a lot of products require like the first problem you can notice here is that you are allowed to read declare this video you're actually redeclaring a and you can redeclare this multiple times and you can save any value inside of them you can save a number string and you can basically declare you can actually re-initialize you can reassign the values here with where keyword but this sometimes becomes a security issue this is a big security issue because of course if you have a large application and you are allowed to redeclare a variable if by a mistake anyone redeclares a variable the value of that variable will change forever and that is not something that you want right so this was the first problem so this is the first problem with where right so let me just write this problems with where problems with the war keyword is that redeclaration is a noun pre-declaration is allowed which shouldn't be allowed right so to tackle this problem let keyword comes into picture we'll see how light will solve this problem now the second problem with where keyword is it is function script now what is functions code what is Blossom okay welcome to that first of all let's just solve this problem right so here if you see very very we have redeclared this so many times and it is uh it is good enough to run a program it will it will not uh through any error it will not show anything like that but if we use the red keyword if we use a net keyword let me say let see equal to we'll say hello and I'll just print this over here I'll just print this let uh see over here so it will obviously it will print hello right but what I cannot do is I cannot do this again if I say this 30. so you can clearly see that this is actually showing main error okay and this error is cannot re-declare blocked variable because of course we can redeclare the variable when we are using wire keyboard but this problem let us solving by actually not allowing us to redeclare any variable out here right so this is a problem let keyword is solve it so if we run this code now and let me just type console.log c over here also and uh let's just comment this code and I can go and I can run this code now so I'll just say node this is the code right so I'll just say node variable dot JS I'll run this file and now you can see the terminal has thrown us an error and it says identifier C has already been declared identifier C has already been clear so you cannot read declare this variable now so this is what the difference a bit this is the first difference between wire and lettuce right but but reassigning is allowed with net reassigning redeclaration this is basically redeculation because you can see we can we are actually redeclaring the variable but if I just do this this is about like any other programming language the assigning is uh unless it's a constant variable right so here it is let's see is equal to hello we are console logging hello and then we are reassigning this value to 30 and now it is unlocked now it is allowed so if we run this code now if we run this code over here now so we'll see node variable.js and you can see Hello in 30 right sorry but there is a third keyword there is a third key that is known as the const keyword there is another consumer and as the name suggests const is basically for defining anything as a constant right so if I just let me just say welcome to Scala so now I will just print this here and let's just run this corner so you can see Hello 30 which is basically coming from this let variables and this and then it's coming we'll come to scalar from this const but what you cannot do here is you cannot re-declare this and you cannot reassign this Inlet you are only allowed to reassign you were not allowed to read declare in what you were allowed to do both you could also re-declare right you could re-declaring re-declaring and reassigning both the things were allowed here but with that keyword there was only vsi you cannot re-declare this right so I'll just say really the sign but with const keyword nothing is allowed no no directed no redeclaration no reassignment all right so what you can do is you can just try this out by doing this cons D equal to uh goodbye or you can just say cons D equal to we can just reassign this as the equal to 50 or something like that right so this is not showing any error this is not showing any error but it is not alone so let me just quickly show you this if I go and console log deal here so what you will see you'll scan here right let me just run this node one variable.js okay so we are thrown an error the terminal as shown as an error and that's this assignment to constant variable this error will come in because we are actually reassigning a constant variable a constant variable cannot be redeclared a constant variable cannot be reassigned all right so this is basically about these three keywords of JavaScript that is where there is Let There is const and we actually discussed we actually discussed their first properties right that how do they work so let me just erase this and let me just create a little table over here so this is basically VAR okay this is what where we are allowed to re-declare and we're allowed to reassign we're allowed to do both then there is let where you're only allowed to reassign then there is const where you are only allowed to declare this variable or point back no reassignment no red declaration all right so this was uh the first thing that we need to learn about the variables and the keywords there are two or three more differences that we need to see on where letting const but therefore another time all right so this is the basic of how you can declare variables right so just try and play around with it for a while uh declare some variables print memorable right and do that stuff and after this we'll be moving to arrays and checks so now let us discuss about arrays that what are arrays why do we need them and what purpose do this on right so array is basically a data structure there is a data structure that will help you to store multiple values to store multiple values at once right so Aries particularly a data structure in which what you can do is you can store multiple values at once like let's just see how you can initialize an array right so you will understand that better so what I'll do is I'll just create a new file here I'll say two underscore arrays.js and so here here we have created a file and we'll just close all these files for now all right so yep let's just see so first of all we need to understand how you can initialize an array so to initialize an array this is a very simple way in JavaScript you just need to declare a variable I'm using let here so I'll say let ARR equal to just square brackets right so this is how you can initialize an array and inside the square brackets you can put all the values that you want right so let's just suppose that we uh so I'll just write it right here initializing an array right initializing anyway now let's just see how you can initialize and how you can put values inside it so for example uh let's say that we have multiple fruits right we have multiple fruits and we have a task to create an area of those fruits so what we'll do is we'll just go here I'll just go here I'll just type let fruits equal to and how you can initialize with the square bracket and inside the square bracket you can basically use single quotes or double quotes right there is no compulsion in JavaScript for using singular double quotes for Strings so what you can do is you can just use single quotes this is basically recommended and inside the single quotes you can name your fruit like suppose I give the name mango here and then we have apple and then we have orange and so on you can add many as many as fruits as you want right so I'll just do this in a single point but so in this way you can actually create an area basically what you're doing is you are storing multiple values at once inside this data structure right but there is a catch there is one important thing about array is that these values will always be indexed these values will always be indexed what do I mean by that uh basically the basic behavior of array is that it will actually give particular indexes to these particular values so that we can refer them at a later stage of time and the indexing starts from zero so basically your first uh element your first array element will start from the index 0 your second element will basically have the index plus one that means it will have the index one and then this orange element that has a third element it will basically have the index of three so basically what you can say that uh the longer your area is basically the length of your array right so you will always have your index from 0 to n minus 1 where n is your last element right for suppose you have 0 1 uh sorry this will be two little mistake this way so 0 1 2 all right so you have three elements but it's starting from zero and it's ending at two so basically you have three elements but your index is what n minus 1 basically three minus 1 that is 2 right so this is how area will work simple answer it will always have indexed uh it will it will always have indexes that will basically help you to refer all your elements one by one right so this is how you can initialize an array so the next thing that we need to see is that how can you access the element of an array so what can you do this you can just go in and you can just say that you need to access this apple from this array right so what you can do is you can just go you can say that let her happen equal to this is the fruits array so what you will do is you will just say fruits that means you are referring to this area that bring me this area and inside this area what I need is I need the first index first that as we have discussed this will be 0 this will be 1 and this will be 2 right so we need the first indexed element we need the first indexes element the element that is at the first index so what we can do is we can just pass Square array basically square brackets and inside the square brackets we can just say one all right so what this will bring me is when I'm in console log this happen Apple element uh let me say put an element and when we'll run this code so now you can see this is actually logging apple right so what what it what it has done is it has basically gone to the first index it has uh looked at the first index what what value is there it picked that value and it has returned it to us all right so this is the way you can access element from an array so I'll just write here accessing element from an array accessing particular element right so this is how basically arrays will work so there are a lot more things that we need to know about any so let's just go one by one over them so in JavaScript in JavaScript now uh you have noticed here what we have done is we have basically stored same kind of data in this area right these three things are all strings right mango apple or in there all strings and in other programming language in statically type programming language mostly there is a compulsion there is a compulsion that in a rate that an array can only have can only have same kind of data that means the data type of all the elements should be same but in JavaScript in JavaScript this does not stand true because JavaScript is dynamically typed as we have seen earlier so arrays are also dynamic in JavaScript so what you can do is you can actually store like if I say let my array I'm creating another area here so inside this area what you can do is you can actually store different values of different data types right so let me just say that hello this is my first value this is a string then I can also say two separated by a comma right so this will be my second element basically the first index element then you can say true this is my Boolean value you can also store it here then you can also say that we have stored a string we have stored a number we have store so so we have stored a Boolean value then you can also again you can store a string right so there is no compulsion there is totally no compulsion that an array should have same kind of data they're starting like it it can have anything so if we just console log this array you'll see that it is perfectly fine and it will print right so let's just open node here it is right so this is an array in which we have value hello to True goodbye like that so basically this is how array will be able JavaScript so when we will discuss object I will let you know that how arrays are also objects right but as we have known as we have not gone into objects that deeply so I'll not confuse you right now so what we can do is uh we can now see that uh how are different methods can work with arrays how can you use different method with with arrays to add element to remove element right to manipulate your array a little bit so let's just get started with the methods now all right so now let us see uh what are the different array methods what are the different area methods that you can use with JavaScript basically that you can use to manipulate your array to play around with array right that you can use any methods that you can use so the first method that I will be discussing is the push method right so okay so what you will do if you want to add an element in your array right adding an element in here basically by discussing that so one thing is that if you will go and you will statically add an element here right like anything or something like that you'll just add an element here but not everything will be statically done right you will have to perform some Dynamic operation sometimes so what you will do is you will get a data from somewhere and then you'll have to add that to your array so you will have to perform something like that all right so what you can do is you can use the push method to add a data in your array so what push method will do is it will actually go to the end of your array and it will add the data there right so if you see Hello to true and goodbye so these are the four elements that we have in our array what if we want to add an element after goodbye right what if we want to add an element after goodbye so we can just use a push method so what we'll do is we'll just use my array because that is the area we want to because that is the array at which we want to add the element and in this variable just use this push method and we'll just say anything whatever you want to add right so if I say I want to add watermelon let's just use this fruits array so this will make sense so I'll just use this flute area and I'll add watermelon in it right so what will happen is uh basically this push method what we do it will do is it will just take this uh fruits area and it what it will do is it will just push watermelon it'll just push watermelon after Orange right so let's just uh run this code and see that so note all right so we haven't printed this fruit element what I will do is I'll just come here and I'll consult out the fruit element also fruit area also so here you can see that mango Apple orange and here we have watermelon also so what does push method will do it will actually add an element that's an element at the end open array right so this is what push method does of course there is one method that is known as Pop method so as push method was adding an element at the end of an area what pop method will do is pop method will basically do the opposite it will remove the elementary it it will remove the element from the end all right so what we can do is we can just go here we can just say Roots dot pop and that's it that's it so fruit dot pop will automatically identify the last element that is inside this array and now it will remove that element again so it will remove that element basically so let's just go and console log the fruit area again and see that this has worked or not so what will happen is We have basically modified the fruits element with watermelon so now our array has now our array has a basically it has a mango Orange apple and watermelon right so what pop method will do is it will just remove the last element that is the watermelon right so let's just see we'll just go here we'll just say node and you can see that this was the modified array when we pushed watermelon inside it and then we were popping it so uh pop what will it what will it do it will basically remove the last element from the array so these were the two methods that are used to remove uh from the last and back to the last push and pop right so uh now let's just discuss some more methods but so uh what if we want to add or remove uh any element from the starting operative from the uh basically starting of an array right so basically here portion but what we want to do is we want to add or remove element from the starting open starting operating right so for that we also have methods the first method is shift method let's discuss friendship first all right so unshift method it will actually allow you it will allow you to add an element at the starting point so how will this method work is basically what we'll do is let's just take this fruits array for example again and with this area we'll be using our unshift method and inside the scientific method you will have to pass what element you want to add so I'll just pass a banana here and I'll just go and we'll print the fruits area again right so let's just go and run this code I'll say node and this is my file name so now you can see that banana has been added at the first index at the zeroth index so what uh unshift method has done is it has just taken this value and it has added this value in the first index of an array that is basically the zeroth index right so this is how unshift works and if you want to remove an element from your starting of an array what you can use is you can use a similar method like push and power the there is unshifted shift so you can use the shift method over here so it will basically help you choose remove an element from the starting of an event right so this is how they'll work and let me just write something for this as well so I'll just say fruits dot shift right so as I have write two dot approach dot shift and when will console log this what it will do is we can guess it will remove banana for you right so that's it so here we'll go and we'll just try open with the terminal mode so basically now you can see this updated edit banana has been removed from here and this is because of the shift Method All right so these are the four methods that we discussed push pop unshift and shift what push will do is it will add an element at the end pop will basically remove an element from the end unshift will add the add an element at the starting of an array and shift will remove the element from the starting of an array so these are the four methods that we discussed so let's just go further and discuss some more methods so this is how basically Aries work right so uh there is a lot more stuff there is a lot more stuff that you can do with arrays like you can you you can also use a hardware function you can use spread operator to glue on an array and all that stuff but we do not have a better understanding of objects right now so what we'll do is we'll just go through objects once we'll understand objects went deeply objects once deeply and uh then we'll move on to further like in further videos we'll move on to uh different things you can do with arrays right so uh let's just move on to objects now so what I'll do is I'll just create another file over here and I'll say three underscore objects so here we'll start with JavaScript objects right so let's just stop so in JavaScript objects are basically collection of data in key value pair yes it's basically a collection of data for a particular object that will contain its properties in Key value pair right so uh for example let me just create an object over here I'll say let person right let person and I'll initialize this as an object to initialize a variable as an object what you have to do is you'll just like in Array you used to initialize an area with a square bracket here we'll just initialize your object with the curly braces that is the curved brackets here so this is how you can initialize an object and now what you can do is you can just add some properties about this person object in key value pair like for example what can a person have a person can have a name so we'll just add a name suppose we added Adam all right then you can separate this property with the comma you can add another property with another key let's just say h and we'll say uh atom is 23 right so this is Adam and here is his phone number so we can say anything right for example just I'm writing any random numbers so this is how you can actually create an object that will basically store uh details or properties of this particular object in the form of key value pair where this name is the key and item is the value age is the key 23 is the value phone is the key and this random number is the value all right so in this way uh JavaScript stores properties right for a particular object now if you want to access any of these properties what you can do is there are two notations there are two notations by which you can actually access any property or any value inside of an object from inside of an object so the first thing is the dot rotation like for example if you want to access this name property from this object what you can do is you can just say I'll just console.l of this and I'll say person I'll refer to this object dot I'll get the name output so person dot name so uh let me just print an object first so you will see how object gets printed I'll print the whole person object first so you'll see that this is how it will get printed so I'll just say node and three object.js here so this is basically an object right where we have name age and four which is similar to this object right this object is basically printed here now to access some particular properties from the object what you can do is you can use the dot notation so this is basically the dot rotation where you are actually calling a property by just adding a DOT and the keys name right so here the object is percent and the key basically is the name so what it will do is it will bring the value out of that key person.name has the value atom so by this we are expecting to print addict so let's just try this so you can see Adam is getting printed here this is the object basically we don't need this console.log anymore right so this is here item is getting printed right so this is a DOT notation and there is one more notation that is the bracket notation by which you can access any property of an object so let's just quickly see that also bracket notation so what we'll do is we'll just console lock will again call the person object and inside bracket inside square bracket in under string right under string what will pass will pass the name of the will pass basically the keys name right so here the keys name is name age phone you can pass anything but it should be inside a string so you will pass phone suppose like that and so it will basically bring out the phone key and the the particular value of the key so let's just run this again and we'll see what happens so node so you can see that this brings out the number value basically the phone value right so this is how object work in JavaScript this is how you can create an object but not only this object has so many different properties right so uh let's just see uh objects in a little more detail and uh can see what what all uh what else we can do with the object in JavaScript right so let's go ahead so let me just take an example of I'll create an object right and I'll say this is Captain ah I hope you guys are familiar with Captain America right so I'll just create an object of Captain America where I will be defining all the properties related to him right so what I will do is I'll just create a lit captain let Captain America so this is basically the object so what all properties can Captain America have right so he'll he can have his first name so I'll just say first name and I will initialize this first name I'll give it a value of Steve then there can be last name so I'll just give this a value of projects Steve Rogers this is his first name this is his last name all right very nice now now see here I want to show you that inside an object inside the keys of an object you can set any value that you want you can set any value that you bought right so not uh not only string or not only numbers you can set any value that you would like if I go and I say is Avenger and if I set this true that's also perfectly valid inside of an object so you can set string in the keys you can set Boolean in the keys and of course let me just say Captain America has friends right so you can also initialize an array inside an object so that you can have multiple multiple values here like he has he had a lot more he had many teammates he had multiple teammates right uh so what I can say is I can just say for I can say uh to restart you can say Bucky Barnes and so on you understand it really so now you can also store arrays inside of keys then you can also sorry it's not a semicolon a comma so friends we can store array we can basically uh store Boolean values we can basically store strings and let me just store his age so we can actually store numbers right we can do all those stuff like that we can also store nested objects inside an object so uh let me just go and grab something as address I have initialized a key named as address and this address will basically have multiple properties right address has multiple properties uh state city pin code Etc and all that so we can also make a nested object inside of an object so can we do that we can just do that by doing this that we created an address and we can say that this is an object and inside this object we have multiple values like we have state convert this dot state state key and in this state key we have New York and for the city we can type Manhattan or Brooklyn I don't know I mean I'm just writing all this randomly just to make you understand so state New York City Brooklyn so you you can just write your properties like that inside of an object so you can string a Boolean basically you can initialize an array you can put a number you can put a nested object you can also create functions you can also create function inside of an object but I'll let you I'll tell you about functions when we'll get to the function guys we have not discussed functions a lot we're discussing functions over here all right so this is how you can create an object right so now what we can do is how can we access these values how can we access this values so there are two notations that we first discussed one is the dot notation the second one is the bracket notation so what I'll be doing is I'll be using dot notation over here to access some values like if I want to access friends if I want to access these This spells array what I can do is I can just say console.log and I can go to the Captain America object inside of which I need friends and so this will give me the whole array but what if I need some specific uh element from this array like I need Tony Stark for example so here the array fundamentals will follow the array property will follow like the array is always indexed so if this is zeroth Index this will be my first index so what I can do is I can just go to friends I can just say bring me the first Index right and if you run this if you run this now so you will see that Tony Stark is getting printed here that is basically the first index of this array so this is how you can basically initialize object this is how you can basically set the key value Pairs and these are all the things that you can put in inside a key of an object right you can also put function but we'll get to that later and now you can print all this values and you can play around with all these keys so this is basically a basic structure of how an object is created inside of JavaScript right so there are different things that we can do here uh that means we can say uh we can view you can access you can also access this uh address listed object here right so uh this is the basic structure of object inside JavaScript so now if you want to add something to this object you can also do that if you want to remove something from this object you can also do that we have all the means for that as well so if you want to add something in this object so what we can do is we can just refer to this object and if we want to add a new property like there is no movies property here so what I will say is Captain America dot movies and I will make this as an array and I'll just add some movies like I will add like I will add Age of Ultron or let's just add Civil War or something and let me just add one more end game right so you can see I've added three movies here so now if I will print this object now if I want to print this whole object that is the captain numerical object so now you will see that a movies key will be added to this uh whole object and you will also see these values there right let me just run this again so I'll just say node and now you can see this that in the end a movie's property has been added with these values that we just pushed here right so uh this is how basically you can actually also add something to your object now there is a there is a thing by which you can also delete something from your object so there is a delete keyword that you can use and you can just pass the object and you can pass the key like suppose I want to delete the edge so I'll just write delete and I'll say uh from which object and what property I need to delete and I can just say this and this will basically delete this property from my object so now if I console log my object so you will see that that particular age property you can see here is each property but whenever I'll console this it will not be there so let me just go back and run this code so now I can see now my object does not have the H property it has been deleted so this is how you can basically add your property you can delete your property if you want to update your property like if you want to update is Avenger so you can just take this property and you can set it to something else uh like if I go there if I go here and I say Captain America dot is Avenger right and I set it to false that no it's not an event so what will happen is that this will set it to false so now whenever you will look at this object whenever you look at this object you will see that the value is will be set to false so if I run this code uh sorry I misspelled this what else so now you can see that is Avenger is actually what's up so uh this is how you can actually update your object you can add something to your object you can delete something from your object uh so this is the basic idea of object in JavaScript uh we'll be doing a lot more stuff with objects uh further but uh to start with objects I think this much is enough for now so yeah so we have discussed variables we have discussed arrays we have discussed objects now the last thing that we want to discuss in this video is the functions are the functions in JavaScript our functions will work what is the purpose of functions how to initialize how to create how to declare uh what a parameters what are arguments uh all that thing will be seen next right so I'll just create a file over here and I'll say four underscore functions cheers so in this file basically we'll be creating functions and we'll be learning all about functions so let's get started with functions now okay so now let us discuss functions right what are functions so uh let me just go to the board and just let you know what are functions so basically if we Define functions so functions are just a piece of code functions are just piece of code that runs when you call it right so it can also take inputs and according to those inputs whatever instruction that you have passed inside that function it will take this inputs it will process these inputs according to that particular instruction that you have passed right that what you have to do with this input and it will give you a specific output that is basically required out of it right so this is basically what a function is it is a piece of code that will execute when you need to call it right you just write it and after some time you can call it so it will actually do the task for you okay so for example let's just go to our IDE and here I have created a file for function.js and here I'll be writing a normal function right so first of all let me just write how will you declare a function right how will you declare or Define a function so what you do is you need to add this function keyword you need to add this function keyword to declare or Define your function so here I will say function and I'll say greet right function grid double brackets and I'll open this so this is your function body this is basically a function body you have defined the function and now this is your function body here you can actually Define a function that what your function will do right so it will basically do it will console log hello from scale so this is the task of this function and as I said this is a particular piece of code which you can call at any stage of a program wherever you want right so I'll just call it here okay and how you can call it you will just have to name this function right you just have to name this function and I mean you just have to take the name of this function and you have to add these brackets so this is known as function called or function invocation right so what it will do is whenever you will call it it will actually refer to this grid function and whatever is basically the task of this function this will happen then right so let me just quickly run this for you so I will come here okay I have opened a lot of files I'll just close everything all right and I'll just come here I'll say function and I'll say node 4. so this is how and here you can see hello from scale which is basically the task of this particular function right so this is how what you can do is this is how you can create function and this is how you can call your function so this is known as function creation function declaration when the definition whatever you can say and this is basically the function invocation right function invocation functioning location and this is your function call or you can call it right but this function this function can also take in inputs this function can also take in inputs so what we can do is let's just create a simple function for adding two numbers right so what I will do is I'll just say function and I'll name this function as ADD and here what I will do is I'll pass a comma B I'll pass a comma B so this a l comma B these are basically the expected input values that will pass when we will be calling this function right so at this stage of time this A and B these things the this is known as parameter of a function parameter of a function basically parameters of a function right A and B are the parameters of a function basically what is expected out of this function that what it is expecting from uh are the parents so it is basically expecting two values to be passed and by getting these two values what it will do is it will basically add these two numbers this will add a plus b right so let's just call this function and now when we are calling this function we have to pass the values that will go into a and b right so let's just say I am passing 2 and 3. so now when I am passing these values I am passing these as arguments these are known as Arguments for these parameters right whenever you are defining a function you are actually expecting some parameters and whenever calling it you're passing the arguments for that parameters right so whenever you will call it let me just comment this one out and let's just focus on this body over here so this body will take 2 and 3 as values and we'll call this function it will add these two values and will produce the output so what it will give you if I run this code so it will give you 5 of course right so this is how you can actually create a function this is how you can actually pass the parameter this is how you can pass your arguments right so this is how a basic function works so what I need you to do is you just uh write the functions of subtraction multiplication and division and let's just get done with it right so I hope you would be able to do that I'm not doing it you can easily do that you just need to change this names and you just need to change the operator here right so you can do that so this is our basically a basic function works but in JavaScript but in JavaScript functions also works as variables so how will a function work as a variable right so that is basically the first class citizen concept of function that is basically the function expression concept right so what we can do is we can also write a function like this we can actually include a function inside a variable let me just say that we have created a function add here so let me just create a function sub here right I'll just create a variable name server what I'll do is I will I will create a function inside of it and I'll say that it also takes two parameters and it will also print the result of that subtraction right C minus B so now what you can do is you can basically use this sub as a function because now this variable has this whole function inside of it right and this concept is basically known as functions as first class citizens or this is also known as the function expression because what you are doing is you are actually including a function inside of a variable and this is perfectly valid in JavaScript you can do this so now if you call this sub if you call this sub with 3 and suppose one so what will be the output it will be there subtraction right that will give you two so let's just see not three to fourth one uh B is not defined where okay sorry this is d so you can see it's also giving the output as 2 right so this is known as a function expression right and this is how you write a normal function that means a regular function right so this is how you can actually do this kind of stuff so there is one more concept that I need you to tell this that is known as so basically uh you must be thinking that what is the difference between this and this basically both are serving the same purposes but when will go uh deep into uh the topics like hoisting and stuff then you will understand that how our function expressions are different from regular function and what purpose are this following basically using this function expression are uh more recommended it is recommended to use functions as expressions and why is that it is because of hoisting so when we will get deep into hoisting we'll actually understand that why writing functions as expression is better than writing regular function right so uh this is how you can actually this is these are the two ways in which you can actually create function right there is another type of function that is known as Arrow functions but will get entered a little data uh so the next thing that I wanted to tell you is about the hippie so if he is basically immediately invote function expression right immediately in your puncture expression like here you can see that we have defined a function here and then we have called it at a later stage of type we have defined the function here and then we have called it a later stage of time but what is basically iffy that you basically Define a function right there and that is called right there all right it will be immediately called you will not have to go you will not be allowed to call it at a later stage of time you'll be needed to write that function over there and it will call that function over there only and it will finish doing its work right you cannot call it at a later stage of time so that is basically an if we uh which basically immediate language it is immediately right uh by the name it's clear so how can you create an Epi how can you create an FP so let's just create an AP for multiplying so I'll just say multiply and you have to add this round brackets first you have to add this round bracket first inside this you will need to initialize your function you'll need to pass your parameters that what are you expecting out of it and then you can normally Define this function over here and I'll say that multiply these numbers whatever will pass but now you cannot call this like this you cannot call this like this right this will throw an error what you have to do is you have to pass you have to pass your arguments over here you have to pass your arguments over here like you have to pass this arguments in the bracket outside right 20 and 30 supports I have passed this or I have five just passed two or three right so whenever I'll pass to a 3 over here what it will do is it will take this this 2 and 3 as an argument and it will pass into this parameter it will call this function and basically it will print uh a into B right so let's just go and let's just run this so what else is node four and here we can see that you have got the output as six that is basically 2 into 6. so these are all the ways in JavaScript that you can create functions uh first one is the regular function how you can create this second one is function expression by basically including a function inside of a variable and then third is the AP so if we have some limited applications we'll discuss about them that where this comes pretty handy right or so these are the things and then there is a type of function there is a new type of function that is introduced in es6 that is the arrow function so we'll be discussing over that as well but to start with JavaScript we have discussed today about variables we have discussed about arrays we have discussed about objects and we have to convert functions so this much knowledge of JavaScript is enough so that we can start with the node fundamentals you know we can actually go a little advanced in all those topics and yeah so this was pretty much it about this video and uh I'll see you on the next video with some more advanced concept with some more topics and we'll discuss it from there do subscribe to our Channel and if you like the and if you like the video please give us a like subscribe to our Channel we'll see you on my next video thank you so much