Basic Concepts of Variables By Digital Marketing Agency Mumbai

Basic Concepts of Variables By Digital Marketing Agency Mumbai

Chris

Another type that variables can be booleans and this is used all the time so we can save us a hand. Let's see which variable name Bare and Chris equals true. So this is now a boolean true or false. So if we say and Chris we're run we can see that he returns to us as true if we change the name to Bob. This, of course, is not Chris. This is Bob. So am Chris tested out false or is this kind of a silly example but true or false. The basic concept introduced by digital marketing agency Mumbai regarding variables may be different.

As you can imagine are pretty useful when you're developing an app. So, for example, has the app started to were false has the counter started tour false. Has this happened? Has that happened? All different kinds of ways that we would need to kind of check this flag is false. Yes or no. Another tape is no. So am I. No. So no is basically nonexistence if we checked this, am I? No clear run it's no right. So if you need to say initialized something you could initialize it as No.

You could also just say Varnell declare the variable without signing it a value. In this case, undefined not quite the same as No. But similar. You should check a quick list of digital marketing companies in Delhi NCR 2019. So you could do em I know and then later on in the program you could say am I. No. Equals false. At this point, am I know is now false. Or let's clear it to run again. So here it's false.

So really variables are pretty straightforward. At their core and you know you're going to be playing a lot with variables once you start to actually write javascript. So you just need to understand what they are how they could be used. Learn javascript, programming from digital marketing agency Mumbai India. Another thing we're going to need to key in on is something called scope. So we've kind of seen it a little bit already without realizing it.

So variables can have different kinds of scope in an app and that's something that iOS addresses as well. But just as an example of that let's say we have a variable My name we can't slug it out we know what it's going to show us. Console log my name. Let's clear it. We'll run it. We know that it's going to tell us, Bob. But what if we have said some kind of function.

So let's add some space here in between. The function will say the name so function says the name it and what this will do is this will cancel the log. My name is all right. Then we can invoke the function down here say loop say the name and the or semi-colon here. So we know what's going to happen if we hit run. The digital marketing agency Mumbai have different program frameworks of Javascript. It's going to say Bob what if we reassign the variable var right here we're declaring a new variable. So we're not re-assigning we're declaring a new variable.

It's going to say Chris and you would expect this would say, Chris. Right. You would be correct. But if Down here we check again what's the console logs say for my name run it again. OK, so we see two different results. It's kind of the danger of having the ability to read you know redeclare a variable and the difference comes down to scope. So this my name variable is confined to this function. It's a locally scoped variable confined to this function.

This because we don't define it within a function we don't really give it any parameters. It's a global variable. We can access this from anywhere. I should also mention that it is really bad practice to be re-know declaring variables with the same name. This is not something you would want to do in a production app or any kind of production code because Which one is which you know you're Linter or your text editor would probably throw up an error saying hey, you can't redeclare a variable with the same name.

It is valid however and it will work as we've seen here. This is just a different scope. So my name here it's confined to the scope of say name whereas up here it's just declared globally. Now if we were to read declare or not redeclare. The variables concept learning from digital marketing agency Mumbai isn't hard. But you know re-assign is variable. Instead of declaring variable again we just say my name is now equal to Chris. Let's see what happens. Run it. OK, so it says Bob and Chris again.

But what if we move our cancel log here. So instead of doing it before invoking the function, we do it after we invoke the function. Clear or run it. So here the function runs and you know this code is you know it does happen sequentially so same name is called.

Then after sending in, it's called cancel log is called that which we've already read declared the variable. But if we declare it as a new variable instead we don't come across that issue. So it's kind of a double edged sword sometimes it might be good to be able to redeclare a variable. Other times usually no.

You know I would err on the side of caution it's usually not a good practice to be redeclaring variables with the same variable name especially if you consider you know your app might have thousands of lines of code and you have to kind of track through to figure out oh geez I use the same variable name here and also down here. Now my app is crashing and I don't know why.

So definitely something you would want to be aware of when selecting a digital marketing agency Mumbai. You know we'll look at strategies to mitigate that with ESX as well. Other things we need to be aware of in terms of declaring variables is that there are certain reserved keywords in javascript and normally it'll just kind of throw up an error if you try to use one. For example, you can't use var true you can't name a variable. True or false.

This is a reserved word. You can't do something like this virtue equals true. If I were over this I expect the identifier and instead saw true which is, of course, a reserved word in Javascript. If you try to run it you know it's just going to crash it gives us an error unexpected token true and here we already knew that would happen right because there are Linter told us this would happen.

You know it usually you won't come across this problem because your variables should be fairly descriptive like, for example, var is started equals false. For example, this is a good way to initialize this false. So whatever you're doing if you want to keep track of if something is started using a true or false Boolean this is a good example of a nice variable to use or you wouldn't want to be something like that.

Are false equals false? This wouldn't work of course other reserved words you know you can always Google digital marketing agency Mumbai but often you're Linter will tell you as well so you can't say something like. Class. No, you can't say var equals something. Right. This would also not work it's going to tell us hey var is a reserved word. Let's try to run it. Error. Right.

So it's looking for a variable name afterward here but we just redeclare var again. You know it crashes with good reason so it's a reserved word. They're generally speaking what you would expect them to be or you can't say var no equals something you will not like that expect identifier and that's. No, that reserved word. So there's a number of these. You know just using good judgment. Generally, if you think you shouldn't be using something like a variable name you probably shouldn't be.

Report Page