Variables are fundamentals concept of every programing language. They are used to allocate space in memory to store information in form of so called “data” so later by referring to variable we can get its value.
What is variable?
Variables are fundamentals concept of every programing language. They are used to allocate a space in memory of an operating system to store information in form of so called “data”, in which that information within the variable can be used over and over later on that code, program.
Variables: are boxes or containers which allocate space in memory of an operating system to store data, information within that space.
var keyboard following by name of variable and then assigning or storing data to that variable.
In example above we used var keyboard to declare a, b and c variables. However there are two other keywords
Now, we have 3 ways of declaring variables. We will discuss the difference and usages between the 3 later in this lesson.
This is an important step of using variables in any programming language to assign a value or data to variable using
= sign, so we can later use that variable within our code.
In this example person is declared as variables where John is assigned as value or data to this variable. Later we can refer to person variable to get it’s value.
Let’s summarize what we learned:
personis the name of the variable
Johnis the data, information or value we stored within person variable
numberfloating point number, decimal or integer
stringsequence of characters, text
booleaneither true or false values
objectused for rather complex data structures
symbolto represent unique identifiers
undefineddeclared variable has no value yet
- Names should begin with lowercase string
- Names cannot begin with symbol, or containing any symbol
- Names can only start with _ symbol
- Names cannot begin with a number
- Names can contain a mix of uppercase and lowercase characters or numbers
Naming best practice:
Most common ways of variable naming among developers are camelCase and under_score for variable names more one keyword.