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
- 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";
- 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;
- Boolean Booleans represent logical entities and can have only two values: - trueor- false.javascript- let x = true; let y = false;
- Object Objects are complex data types that can hold multiple values in key-value pairs. javascript- let student = {rno: 1001, name: "ravi kumar"};
- 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"];
- 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; } }
- Symbol Symbols are unique and immutable data types used to create hidden properties on objects. javascript- let sym = Symbol('unique');
- Null - Nullrepresents the intentional absence of any object value. It creates a reference and then destroys the memory.javascript- let x = null;
- Undefined - Undefinedmeans a variable has been declared but not assigned a value. It does not hold any reference.javascript- let x; let y = undefined;
- Typeof The - typeofoperator is used to check the data type of a variable.javascript- console.log(typeof x); // Output: "undefined"
Assignments
- 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
- 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
- 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
- Feet to Inch Conversion Write a program to convert feet to inches and inches to feet. javascript- // Your logic here
- Print Name in Binary Write a program to print your name in binary. javascript- // Your logic here
Learn Javascript , visit Shiva Concept Solution
.webp)
 
 
 
 
0 تعليقات
POST Answer of Questions and ASK to Doubt