Sobes.tech
Junior

What types of data can be considered complex?

sobes.tech AI

Answer from AI

Complex (object) data types in JavaScript include:

  • Objects (Object): Ordered collections of key-value pairs. They can contain functions, arrays, and other objects.
    // Example object
    const person = {
        name: 'John',
        age: 30
    };
    
  • Arrays (Array): A special type of object designed to store ordered collections of elements.
    // Example array
    const numbers = [1, 2, 3, 4, 5];
    
  • Functions (Function): Objects that can be invoked to execute specific code.
    // Example function
    const greet = function(name) {
        console.log('Hello, ' + name);
    };
    
  • Dates (Date): Objects for working with time and dates.
    // Example Date
    const now = new Date();
    
  • Regular Expressions (RegExp): Objects for working with text patterns.
    // Example RegExp
    const pattern = /abc/;
    
  • Maps (Map): Collection of key-value pairs where keys can be of any data type.
    // Example Map
    const myMap = new Map();
    myMap.set('a', 1);
    myMap.set('b', 2);
    
  • Sets (Set): Collection of unique values of any type.
    // Example Set
    const mySet = new Set([1, 2, 2, 3]); // Contains only 1, 2, 3
    
  • Symbols (Symbol): Unique and immutable primitive values that can be used as property keys to avoid naming conflicts. Although Symbol is a primitive by nature, it is often considered a complex type due to its specific use in objects and its uniqueness, which distinguishes it from other primitives.
    // Example Symbol
    const mySymbol = Symbol('description');
    const obj = {
        [mySymbol]: 'unique value'
    };
    

Unlike primitive types, complex data types are stored in memory by reference.

What types of data can be considered complex? — Node.js - sobes.tech