Data type concept in Javascript | Javascript Datatype in simple way

0

 Data type in JavaScript:

JavaScript is a versatile and powerful programming language widely used for web development. One of its key features is its flexibility in handling data types. JavaScript is a loosely coupled language, which means it determines the data type of a variable at runtime. This provides flexibility, allowing variables to store any type of data. Let's dive into the different data types in JavaScript and understand their significance.

Why Data Types Matter

Data types help in determining the size of data in memory and dictate what kind of operations can be performed on the data. In JavaScript, the data type of a variable can change during the execution of a program, allowing for dynamic and flexible programming.

Scalability of JavaScript Variables

In JavaScript, a variable's memory can scale up and scale down based on the data assigned to it. This dynamic allocation and reallocation of memory make JavaScript efficient in handling varying data sizes.

Types of Data Types in JavaScript

  1. String Strings are used to store textual data. A string is created by enclosing characters in single quotes (''), double quotes (""), or backticks (`).

    javascript
    let x = 'hello';
    let y = "hello";
    
  2. Number Numbers represent numerical values. JavaScript uses a single type for all numbers, including integers and floating-point numbers.

    javascript
    let x = 10;
    let y = 10.2;
    
  3. Boolean Booleans represent logical entities and can have only two values: true or false.

    javascript
    let x = true;
    let y = false;
    
  4. Object Objects are complex data types that can hold multiple values in key-value pairs.

    javascript
    let student = {rno: 1001, name: "ravi kumar"};
    
  5. Array Arrays are used to store multiple values in a single variable, and the values can be of different types.

    javascript
    let arr = [12, 23, "hello", "hi"];
    
  6. Class Classes are composite data types that can store multiple data type combinations and are used to create objects.

    javascript
    class Complex {
        constructor(a, b) {
            this.a = a;
            this.b = b;
        }
    }
    
  7. Symbol Symbols are unique and immutable data types used to create hidden properties on objects.

    javascript
    let sym = Symbol('unique');
    
  8. Null Null represents the intentional absence of any object value. It creates a reference and then destroys the memory.

    javascript
    let x = null;
    
  9. Undefined Undefined means a variable has been declared but not assigned a value. It does not hold any reference.

    javascript
    let x;
    let y = undefined;
    
  10. Typeof The typeof operator is used to check the data type of a variable.

    javascript
    console.log(typeof x); // Output: "undefined"
    

Assignments

  1. Addition and Multiplication of Complex Numbers Write a program to calculate the addition and multiplication of complex numbers.

    javascript
    let a = "2+3i";
    let b = "4+5i";
    let c = "6+8i";
    
    // Your logic here
    
  2. Salary Calculator Write a program to create a salary calculator where the basic salary, TA, DA, commission, PF, and number of leaves are assigned by the user.

    javascript
    // Your logic here
    
  3. Total Amount Calculation Write a program to calculate the total amount using four different products. Each product contains an ID, name, and price.

    javascript
    let products = [
        {pid: 1, pname: 'laptop', price: 45000},
        // Other products
    ];
    
    // Your logic here
    
  4. Feet to Inch Conversion Write a program to convert feet to inches and inches to feet.

    javascript
    // Your logic here
    
  5. Print Name in Binary Write a program to print your name in binary.

    javascript
    // Your logic here
    


Learn Javascript , visit Shiva Concept Solution




Tags

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)