What is data stucture?
A data structure is a format to organize, manage and store data in a way that
allows efficient access and modification.
A data structure is a collection of data values, the relationships among them,
and the functions or operations that can be applied to that data.
Explain Array?
An array is a collection of items stored at contiguous memory locations.
Each item can be accessed through its index (position) number.
const arr = ['a', 'b', 'c', 'd']
console.log(arr[2]) // c
In JavaScript, we can store values of Any Type in the Same Array
const arr = ['store', 1, 'whatever', 2, 'you want', 3]
Explain Object?
In JavaScript, an object is a collection of key-value pairs.
This data structure is also called dictionary in python.
const obj = {
prop1: "I'm",
prop2: "an",
prop3: "object"
}
An important thing to mention is that each key has to be unique within the
object.
You can't have two keys with the same name.
Objects can store both values and functions. When talking about objects,
values are called properties, and functions are called methods.
const obj = {
prop1: "Hello!",
prop3: function() {console.log("I'm a property dude!")
}}