Variable and datatypes in javascript

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there everyone happy Shearer and welcome to another video of our JavaScript CDs now before we move ahead I just want to give you a brief introduction that I do have a website learn code online dot N and I put a whole lot of courses and in fact advanced version of CDs and stuff on that so please check out that as well now during this entire series I'll give you a brief idea that you can imagine things in the real world and you can see that when I think about building an EPS website like learn code online what's the procedure that's going on behind the scene so that you can relate things with the real-world implementation of the stub this is going to help you a lot in understanding the things also I will be calling up learned code online as an app and it's not just about mobile application anything that's in the computer and that runs and do something is known as a poor application and application doesn't always need to be in mobile anything that runs on the web as well a browser it's also an application running in the browser it can be running up inside the console as well simply a command line app or application so in general for the new people who are just trying to learn programming for the first time yes I will scatter this word word all around the place is calling everything as app or application so please keep that in mind okay so let's just say you want to build an application which is almost similar to learn code online so what's gonna be your first thing first thing is I want to reserve some space in the memory and by that means let's go ahead and reserve some memory in the reserve some space in the memory also known as declaring your variables now we have a whole lot of varieties that how these variables can be stored some permanently some not so permanently and whole bunch of other things goes on around but right now let's just focus on these three keywords and eventually we're gonna talk more about this as we move further the three keywords you're gonna see is varlet and Const again they are very different and they're working flow is very different the most common that you're going to see all around is this Worr keyword war simply means I want to declare a variable and this is gonna store some of the keywords there for example in the learned code online I want to use that what is your name or what is your email what is your password deeds these things need to be stored somewhere and for that in general we're going to use war another keyword is therefore similar purpose which is let and we cannot understand the difference between war and let just right here because a lot needs to be understand for that so let's go ahead and see that how this war can be used now let me open up my vs code and we're going to discuss that there so this is my vs code I have opened up my entire folder here which is Jas tube and I'll keep that as an attachment so that you can check it on my website as well all the files will be available there and I'm gonna create a new folder here and I'm gonna call this one as 0-2 basics we will be creating a bunch of files in this so it's good way that we keep all of them in the separate I'm gonna open this up and I'm gonna call this one zero one and I'm gonna call this as variables and of course don't forget the extension which is dot Jas for JavaScript and we will be running from now onwards the application using node because it's much more easier I don't have to attach it on an HTML I can just directly discuss whatever I want to discuss so the simplest way of declaring the variable there is no such thing as in case you are coming up from C or C++ there is no hash included or something like that there is nothing you just directly start writing your code in JavaScript for example if I just say that I use your full name or I want to store the users full name I'm gonna go ahead use the name full name and then come up simply with the double quotes I want to store this one so I'm gonna write my name here you should be writing your name by now and followed by it you can place a semicolon here now JavaScript is very forgiving about these semicolons but for good practices we're gonna keep this now this bring the the simple conversation about how to name variables this is a big subject and people like to discuss a lot the way how you can define the full name can be a couple of ways you can simply say like this what I say it full name or you could have saved something like this you could have said full - name or you could have saved something like full underscore name and probably you can say something like this full full name so which one is the correct and which one is the best practice that you should go now first and foremost I would like to discard this last here again due to good practices there is nothing to do is this is not gonna give us any error first and foremost whenever you name anything you should not start a variable with the uppercase letter it's generally not a good thing it's not gonna give you any error while defining some classes and all other great things we just use this uppercase letter so there is a specific place where we use it apart from this for these three things I have no problem at all and I have a good reason for that you're gonna see that people says that this is what you should use but people also will come and say that you know what you should use dashes to separate your and make your variable more readable as the name some people will say use snake case yeah these were not known as with a snake case this one is also known as camel case so which one I'd recommend I would say there is no recommendation here just make sure whatever you are using stay consistent don't just use snake case some places some places camel case that's a bad thing to do just make sure you pick up a style and stay consistent with it and that's it that's all about it I usually prefer to use these camel cases because I think they are much more readable so that's what I prefer but in case you are a big fan of using snake cases like you would underscore you can stay with that no problem in that shortly you're gonna have to argue with some kids that says no this is for JavaScript and in C++ we use a dress code there's a lot of kids around here so don't worry too much about them as long as you are consistent that's all it matter okay now you might have noticed that I'm putting up is these double slashes here these double slashes are simply means that I want to comment out this code this code will never be compiled or turned into the machine code this is just for my own reference and there is a quick shortcut for that you can select a number of lines and use controlled slash if you are on a PC if you are on a Mac command slash so it just quickly toggles on these comments on and off so for vs code and most of the redditors so fun thing moving back on to our talk that this is a variable so I have reserved some memory inside I have reserved some memory and I'm calling that memory as full name and that full name actually points to this data that has stored in the memory now JavaScript we got a whole lot of things that we can do let's do a couple of more ones so that we can test out so I'm gonna do another one which is going to be simple course name of course at learned code online we have lots of courses so we put equal sign and then we define every string or the name that I want to say inside these double codes for example I want to say react.js bootcamp that's gonna go just like that so now you know how to reserve some strings here these are strings of course but JavaScript also supports a whole lot of other things for example obviously I'm building an application so there will be people which I would like to check whether they are logged in or not so I'm gonna say available is logged in and I would like to just mark them as true now these are known as boolean types of value there are just two boolean here true and false so that's it that's all that indicated there heavily used in JavaScript and you're gonna see them scattered all around every single place so you can either mark it as true or you can mark it as false again a big thing to remember for big nurse the faults that I've written here and this falls are two different thing in the world of JavaScript the smaller false and smaller true that means these are reserved keywords they have a very specific things to do basically a switching flipping on so false simply means it's 0 and 1 means it's true loosely not 100% but we just say it like that ok whatever semicolon that's one of the thing and since you're building an application you also want to check out that how many times user are actually logging in into your application so let's just say the log count is 30 for some user there we go so we can define the numbers here now great thing to notice here only string goes inside the double codes so what you're seeing here the 34 and if I just wrap it up with a double codes these are two different things this is just a string and this is without the string is actually the number itself when we do the addition it becomes a whole lot of math so make sure you are aware of it right up here so these are a couple of things that we are gonna have here now obviously these are the just the basic ones what also you're gonna see that sometimes you want to declare a variable let's just say somebody wants to do some payment so I'm gonna I'm gonna call this one as payment mode and I'm not putting up any value because I don't know what value is gonna come inside this one anybody can pay with credit cards debit cards bank so I don't know later on when my application runs up then I would like to just add some value on it so I simply go ahead and say payment mode is gonna be simply credit card so in this time I don't put this a wall keyword here because it's already a memory which is reserved so no need to reserve it again just use it for the next time now there is another thing that you're gonna see up here let's do some console.log the very famous thing in JavaScript and see some other things first and foremost we're gonna do a console log here so I'm gonna simply say a console log of logged this one log count so let's go ahead and copy paste this one now notice here there is a difference between the two things first if I make a duplicate of this and I just wrap this up inside the double codes this double quote simply means I want to display this as it is without double quote means I'm referring to a variable whose value should be displayed let's go ahead and save this one and see how this is gonna run so we're gonna simply say node I'm gonna go inside zero to basics and run this file which is 0 1 variable dot GS notice here first time it says 34 because that's actually the value and the second time it just say is logged count so that's it is okay so this was all basics now let's just quickly comment that out how do we did that we simply go ahead and say control slash or command slash that's it pretty easy now let's see what happens when I do a simple console log on this payment mode so I'm gonna actually copy this and paste it up here now you'll be surprised to know that there is another data type that we have to discuss here we have discussed how strings are stored how these boolean values are stored and how numbers can be stored they're a bit more as we are gonna get more friendly we're gonna use them but notice here something strange is gonna come up with the payment mode there is a memory which is reserved but there is no value inside it so in such cases you're gonna see this undefined a lot and in fact we do a lot of case checking with the undefined things as well so notice here once this is being done that's how it is but if I move this one here just below so notice when I save this and run at this time this time it's gonna give me a value so yes there is another data type here which is undefined so in total how many data types are there in fact many I don't want to just get you a bother too much right now just assume there are only these ones you can store strings you can store numbers you can store these boolean values and if you don't store anything that's undefined eventually more are gonna come and we're gonna have a lot of them now just onto a side one we have discussed a lot just one last note I would like to mention here that there are some reserved keyword as well no you don't need to memorize them but eventually you're gonna learn them automatically so you saw that they I have this console being appearing in some different colors similar to this there are some things which are reserved for example if is a reserved keyword so if I just save or if is equals to 23 I cannot do that so how do you are gonna find that if is a reserved keyword obviously good editors are gonna give you some of these hints just like these errors quickly bar if you are still writing on the text pad I don't know why you are just making extra pain for yourself but let's just say use good editors and eventually by the time you will be finished watching this series you're gonna realize that yes there are some reserved keywords which I cannot use so quite a lot of discussion which was fun and we were able to bitly somehow declare our learned code online application now we can take users name course name login count log count as well as we can define the payment method as well so I think that's fun and we are going to just end the video right here and I know you have already subscribed so no need to say that again that's it and let's catch up in next one [Music]
Info
Channel: Hitesh Choudhary
Views: 62,039
Rating: 4.9533334 out of 5
Keywords: Programming, LearnCodeOnline, javascript, javascript for beginners, javascript course, javascript tutorials, learn javascript, udemy, coursera, udacity, learn js online, javascript projects, js tutorials
Id: ycLqC41TO1U
Channel Id: undefined
Length: 12min 47sec (767 seconds)
Published: Wed Jul 08 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.