logo CBCE Skill INDIA

Welcome to CBCE Skill INDIA. An ISO 9001:2015 Certified Autonomous Body | Best Quality Computer and Skills Training Provider Organization. Established Under Indian Trust Act 1882, Govt. of India. Identity No. - IV-190200628, and registered under NITI Aayog Govt. of India. Identity No. - WB/2023/0344555. Also registered under Ministry of Micro, Small & Medium Enterprises - MSME (Govt. of India). Registration Number - UDYAM-WB-06-0031863

JavaScript: Types of Variables


JavaScript: Types of Variables

In JavaScript, variables are used to store and manipulate data. JavaScript is a dynamically typed language, meaning you don't need to specify the data type of a variable explicitly; the type is determined at runtime. There are several types of variables in JavaScript, and they can be broadly categorized into the following:

 

  1. Primitive Data Types:

    • Number: Represents numeric values (integers or floating-point).

      let num = 42;       // integer
      let floatNum = 3.14; // floating-point
    • String: Represents textual data.

      let str = "Hello, World!";
    • Boolean: Represents true or false values.

      let isTrue = true;
      let isFalse = false;
    • Null: Represents the intentional absence of any object value.

      let nullValue = null;
    • Undefined: Represents the uninitialized or undefined value.

      let undefinedValue;
    • Symbol: Introduced in ECMAScript 6, symbols are unique and immutable primitive values, often used as unique identifiers.

      let sym = Symbol("unique");
  2. Object Data Type:

    • Object: Represents a collection of key-value pairs and is a fundamental data structure in JavaScript.
      let person = {
        name: "John",
        age: 30,
        isStudent: false
      };
  3. Special Data Types:

    • BigInt: Introduced in ECMAScript 2020, BigInt is used for representing arbitrarily large integers.
      let bigNum = 123n;
  4. Reference Data Types:

    • Array: Represents an ordered collection of values.

      let numbers = [1, 2, 3, 4, 5];
    • Function: Functions are objects in JavaScript, and you can assign them to variables.

      let add = function (a, b) {
        return a + b;
      };
    • Date: Represents a date and time.

      let currentDate = new Date();
    • RegExp (Regular Expression): Represents a regular expression pattern.

      let regex = /[a-zA-Z]+/;

 

 

These are the basic types of variables in JavaScript. Understanding these types is crucial for effective programming in the language. Keep in mind that JavaScript is a dynamically typed language, so a variable's type can change during runtime.

 

Thank you.

Popular Post:

Give us your feedback!

Your email address will not be published. Required fields are marked *
0 Comments Write Comment