• Variables

    In programming, variables are used to store data values. These values can be of different data types, such as strings, integers, floating-point numbers, boolean, arrays, or objects. Variables are assigned names so that they can be referenced in the code. They can be any size and shape, and can hold anything from numbers to strings of text. You can use variables to keep track of things like user input, or the result of a calculation. The name of a variable can be anything you want, as long as it doesn’t start with a number and isn’t a reserved word in the language. Once a variable is given a value, that value can be changed throughout the program by reassigning the variable. Variables are one of the most important tools in programming, and understanding how to use them is essential to becoming a good programmer.

      • String Variables

      • A string variable is simply a variable that can hold multiple pieces of text (a word, phrase, or sentence). However, sometimes we need to store more than just text. We might want to store a person's name, which can be multiple words. In this case, we need to use a string variable.

      • Javascript

        Example of string variable in javascript.
        var name = 'John';
        console.log(name); // John
      • Integer Variables

      • An integer variable is a data type in computer programming that stores numerical values. Integer variables can be used to represent whole numbers, such as 1, 2, 3, 4, 5, etc. They can also be used to represent negative numbers, such as -1, -2, -3, -4, -5, etc. Integer variables are commonly used in programs to store counts or loop indices.

      • Javascript

        Example of integer variable in javascript.
        var age = 30;
        console.log(age); // 30
      • Float Variables

      • Float variables, like integer variables, hold numerical values but are presented in decimal form. It is possible to represent decimal numbers such as 1.01, 2.20, 3.33, 4.44, 5.555, etc. in float variables. They can also be used to represent negative decimal numbers, such as -1.01, -2.20, -3.33, -4.44, -5.555, etc.

      • Javascript

        Example of float variable in javascript.
        var pi = 3.14;
        console.log(pi); // 3.14
      • Boolean Variables

      • A boolean variable is a type of data that can only have one of two possible values, either true or false. In programming, boolean variables are often used to track whether a certain condition has been met, or to control the flow of a program. For example, a program might use a Boolean variable to keep track of whether a user is logged in or not.

      • Javascript

        Example of boolean variable in javascript.
        var isTruthy = true;
        var isFalsy = false;
        console.log(isTruthy); // true
        console.log(isFalsy); // false
      • Array Variables

      • Array variables are used in many programming languages to store data sets of various sizes. An array is a type of data structure that stores a collection of elements. Each element in the array has a specific index, which can be used to access it.

      • Javascript

        Example of array variable in javascript.
        var fruits = ['apple', 'banana', 'cherry'];
        console.log(fruits[1]); // banana
      • Object Variables

      • An object variable is a type of variable that is used to reference an object. The value of an object variable is an address that identifies the location of the object in memory. When an object is assigned to an object variable, a new reference to the object is created. An object is a type of data structure that holds a collection of properties and methods. For each property and method, a name is used to access them.

      • Javascript

        Example of object variable in javascript.
        class Person {
        	constructor(name, age) {
        		this.name = name;
        		this.age = age;
        	greet() {
        		console.log('Hello my name is ' + this.name);
        var human = new Person('John', 36);
        console.log(human.name); // John
        console.log(human.age); // 36
        human.greet(); // Hello my name is John