Js Data Types 21x51a0596
Js Data Types 21x51a0596
In JavaScript, there are several data types that can be used to store and
manipulate data. Here are the main data types in JavaScript:
1. Primitive Data Types
Primitive data types are the basic building blocks of JavaScript. They are
immutable, meaning their values cannot be changed once they are created.
a. Number
The Number data type represents a numerical value.
javascript
VerifyOpen In EditorEditCopy code
1let x = 10;
2let y = 3.14;
b. String
The String data type represents a sequence of characters.
javascript
VerifyOpen In EditorEditCopy code
1let name = 'John Doe';
2let greeting = "Hello, world!";
c. Boolean
The Boolean data type represents a true or false value.
javascript
VerifyOpen In EditorEditCopy code
1let isAdmin = true;
2let isUser = false;
d. Null
The Null data type represents a null or non-existent value.
javascript
VerifyOpen In EditorEditCopy code
1let x = null;
e. Undefined
The Undefined data type represents an uninitialized or non-existent variable.
javascript
VerifyOpen In EditorEditCopy code
1let x;
2console.log(x); // outputs undefined
2. Complex Data Types
Complex data types are more advanced data types that can store multiple values
or objects.
a. Array
The Array data type represents a collection of values.
javascript
VerifyOpen In EditorEditCopy code
1let colors = ['red', 'green', 'blue'];
2let numbers = [1, 2, 3, 4, 5];
b. Object
The Object data type represents a collection of key-value pairs.
javascript
VerifyOpen In EditorEditCopy code
1let person = { name: 'John Doe', age: 30 };
2let address = { street: '123 Main St', city: 'Anytown', state: 'CA' };
c. Function
The Function data type represents a block of code that can be executed.
javascript
VerifyOpen In EditorEditCopy code
1let greet = function(name) {
2 console.log(`Hello, ${name}!`);
3};
4greet('John Doe'); // outputs "Hello, John Doe!"
3. Symbol
The Symbol data type represents a unique identifier.
javascript
VerifyOpen In EditorEditCopy code
1let sym = Symbol('hello');
2console.log(sym); // outputs Symbol(hello)
4. BigInt
The BigInt data type represents a large integer value.
javascript
VerifyOpen In EditorEditCopy code
1let x = 12345678901234567890n;
2console.log(x); // outputs 12345678901234567890n
Would you like me to elaborate on any of these data types or provide more
examples?