Var in JavaScript

  • Videos
  • January 12, 2022
  • 0

Morten Rand-Hendriksen 

Topics: JavaScript, Var 

Transcript Summary: In JavaScript, the conventional variable is named var. A var is assigned a value by first providing it a name, then using the assignment symbol, equal symbol, and than adding a value to it. For example, let’s assign it a value of five. At any moment, you can call in the container and receive the value. That value will be the number you input. In other words, we can say that the container will notify us if we do this and receive the value. Var is also changeable. We may alter its value and assign it a new value at any time. In addition, you can grab the container and set the value equal to “red” meaning a string of texts. However, if we call the container back by hitting return or space bar, we will get the string “red” in return. The value five is gone and will never resurface unless you reassign the container to the number five. For decades, Var was the default for all variables. It is also the default if we don’t specify that we are creating a new variable. If we were simply to create a random variable, give it a name, than assign it a value without using the “var” keyword, it will seem like a variable. However, the browser will not be happy. If we were to type something equals to seven and hit return, we will have a variable called “something” and if we hit return, we get seven instead. This variable is a var.  

Another advantage of utilizing the var statement is that we can define numerous variables at the same time. So, if we know we will have multiple different variables, we can use a comma separated list to define them all at once. For example, if we make var x equals four, y equals five, and z equals blue and press return. We now have three variables, one of which is x, which is four. y, which equals five, and z, which equals blue. 

We can create variables that do not have any content. We can say var empty and hit return. The variables will be undefined. It also indicates that the variable exists, however, it is empty or undefined. There is nothing assigned to it, so if we were to call back empty, we will see that it is still undefined. Nonetheless, it shows us that it is there, but we need to put something inside it. 

Share:

Access Any Android Device Remotely Without Touching Phone

What is Front-end Web Development?