This content originally appeared on DEV Community and was authored by Mohammad Moiz Ali
In JavaScript, the object data type is used to represent complex data structures. There are three main types of object data types in JavaScript: object, array, and date. In this blog post, we will discuss each of these object data types in detail and provide examples of how to work with them in JavaScript.
Object:
The object data type is used to represent a collection of key-value pairs. An object can be created using the curly braces {}
syntax or the new Object()
syntax. For example:
const person = {
firstName: 'John',
lastName: 'Doe',
age: 30
};
console.log(person); // logs {firstName: "John", lastName: "Doe", age: 30}
In this example, we have created a person
object with three properties: firstName
, lastName
, and age
. The console.log
statement logs the entire person object.
Array:
The array data type is used to represent a collection of values. An array can be created using the square brackets [] syntax or the new Array() syntax. For example:
const fruits = ['apple', 'banana', 'orange'];
console.log(fruits); // logs ["apple", "banana", "orange"]
In this example, we have created a fruits
array with three values: 'apple'
, 'banana'
, and 'orange'
. The console.log
statement logs the entire fruits
array.
Date:
The date data type is used to represent a date and time. Dates can be created using the new Date()
syntax. For example:
const now = new Date();
console.log(now); // logs the current date and time
In this example, we have created a now
date object using the new Date()
syntax. The console.log
statement logs the current date and time.
Conclusion:
The object data type is used to represent complex data structures in JavaScript. There are three main types of object data types in JavaScript: object, array, and date. By understanding how to work with these object data types, you can write more effective and efficient code in your JavaScript programs.
This content originally appeared on DEV Community and was authored by Mohammad Moiz Ali

Mohammad Moiz Ali | Sciencx (2023-04-03T13:43:33+00:00) Understanding Data Types in JavaScript ( Part – 3 ). Retrieved from https://www.scien.cx/2023/04/03/understanding-data-types-in-javascript-part-3/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.