Javascript data types
Created By: chatGPT
JavaScript is a dynamic and versatile programming language that supports several fundamental data types. Understanding these data types is essential for effective coding. Below are the primary data types you will encounter: Primitive Data Types are the most basic types of data in JavaScript. They include:
1. Number: Represents both integer and floating-point numbers. For example:
let age = 30;
let price = 19.99;
2. String: Represents a sequence of characters enclosed in single or double quotes. For example:
let name = 'John';
let greeting = "Hello, world!";
3. Boolean: Represents a logical entity and can have two values: true and false. For example:
let isJavaScriptFun = true;
let isOver18 = false;
4. Undefined: A variable that has been declared but has not yet been assigned a value is of type undefined. For example:
let notAssigned;
console.log(notAssigned); // Outputs: undefined
5. Null: Represents the intentional absence of any object value. For example:
let emptyValue = null;
6. Symbol: Introduced in ES6, symbols are immutable and unique and can be used as object property keys. For example:
let sym = Symbol('description');
7. BigInt: Used for representing integers with arbitrary precision. This is useful for working with large numbers. For example:
Non-Primitive Data Types include: let bigNumber = 1234567890123456789012345678901234567890n;
1. Object: A collection of key-value pairs. Objects can store multiple values and complex data structures. For example:
let person = {
name: 'John',
age: 30,
isStudent: false
};
2. Array: A special type of object used to store ordered collections of values. Arrays can hold multiple data types. For example:
Each data type plays a crucial role in how data is manipulated and stored in JavaScript. Knowing the differences between these types helps in writing efficient and effective code.let colors = ['red', 'green', 'blue'];