Welcome to our comprehensive guide on Data Structures! In this lesson, we'll dive deep into understanding the two main categories of Data Structures: Primitive and Non-Primitive. By the end of this lesson, you'll have a solid foundation to build your programming skills, whether you're a beginner or an intermediate learner.
Primitive data structures are the simplest form of data storage and are built into the programming language itself. They include:
Boolean: A data type that has only two possible values: true or false. Used to represent yes/no, on/off, or true/false conditions.
Number: Stores numerical values, including integers and floating-point numbers.
String: A sequence of characters, enclosed in single quotes (') or double quotes (").
// Boolean
let isStudent = true;
console.log(isStudent); // Output: true
// Number
let age = 25;
console.log(age); // Output: 25
// String
let name = 'John Doe';
console.log(name); // Output: John DoeNon-Primitive data structures, also known as complex data structures, are used to store collections of data. They include:
Arrays: An ordered collection of items, which can be of different data types.
Objects: A collection of key-value pairs, used to store complex data structures.
// Array
let fruits = ['Apple', 'Banana', 'Orange'];
console.log(fruits[0]); // Output: Apple
// Object
let student = {
name: 'John Doe',
age: 25,
country: 'USA'
};
console.log(student.name); // Output: John DoeArrays and Objects can store primitive data types as well. For example, an array can store numbers, strings, or even other arrays and objects.
What are the two main categories of Data Structures?
Now that you have a basic understanding of Primitive and Non-Primitive Data Structures, you're one step closer to mastering Data Structures and Algorithms. In the next lesson, we'll dive deeper into Arrays and Objects, and see how they can be used in real-world projects.
Happy coding! š»š