Storing Information in Variables – JavaScript Basics

Every application needs to be store information and the way we do that in JavaScript or in most programming languages is with variables. We have started with uses of Javascript. Now, we will explore more into javascript features. We are starting this tutorial with Variables.

Let’s take an example of Student Management Software.

What kind of variables do we require to store information?

NameAgeClassGender and so on. Each and every variable has its own type in JavaScript. We will discuss types in upcoming articles. Let’s just concentrate on variables for now.

Variable Naming Conventions in JavaScript

Normally you can define any name for a variable but you need to be a little bit careful about a variable name. For example, if you want to declare Gender variable then don’t just write G or g, it would be very difficult to understand code for a new person when the application complexity level gets increases.

Another thing, when you declare a variable, use camel case formate. It’s a standard way to define variable name across various programming languages.

Variable Declaration Example

 
  // Wrong way (Camel case not used)
   let StudentName = "Garry";

  // Right way (Using camel case)
   let studentName = "Jack";

  // Declare multiple variable (Not convenient way if type is same)
   let studentName = "Jack";
   let studentAddress = "USA";

  // Declare multiple variable (Convenient way if type is same)
   let studentName = "Jack", studentAddress = "USA";
                       //OR
   let studentName = "Jack", 
       studentAddress = "USA";
 

Working Example of JavaScript Variables

 
  let studentName = "Jack", 
      studentAddress = "USA";
  
  console.log(studentName, studentAddress); 
 

See output here in the console window by pressing F12.

We have learned how to declare variables in JavaScript. In the upcoming articles, we will see more on JavaScript basics.

Categories js

Subscribe Now!

Subscribe Us For Latest Articles