JavaScript Data Types
In JavaScript, data types are the different kinds of values you can work with. Let's break them down:
1. Primitive Types (Simple data types)
These are basic types of data that are not objects and have no methods.
- Undefined: This means a variable has been declared but not yet given a value.
- Example:
let a;(Here,aisundefinedbecause it doesn't have a value yet.) - Null: This represents an intentional absence of any object value.
- Example:
let b = null;(Here,bis set to nothing.) - Boolean: This can only be
trueorfalse. - Example:
let isSunny = true; - Number: This is used for both integers and floating-point numbers (decimals).
- Example:
let age = 25;,let price = 19.99; - BigInt: This is used for really large numbers that can’t be represented by the
Numbertype. - Example:
let bigNumber = 1234567890123456789012345678901234567890n; - String: This is used for text, written inside quotes.
- Example:
let name = "John"; - Symbol: This is used to create unique identifiers for objects. You don't need to worry about this much as a beginner.
2. Non-Primitive Types (Complex data types)
These are more complex and can hold collections of values.
- Object: This can store collections of data and more complex entities. Objects can hold properties (key-value pairs).
- Example:
let person = {
name: "John",
age: 30
};
- Example:
let numbers = [1, 2, 3, 4, 5];
- Example:
function greet() {
return "Hello!";
}

Leave a Comment