Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Get Data Type (Main Thread)

Here is the interview question prompt, presented for reference.

Detecting JavaScript Data Types: A Universal Method

The Challenge

Imagine a universe of data types in JavaScript! It's a colorful world with characters like Array, ArrayBuffer, Map, Set, Date, and the mysterious Function. Your mission, should you choose to accept it, is to create a universal method that identifies these inhabitants by their data type name.

Constraints:
- The function should take only one argument—the data object. - We want a universal approach; using multiple if conditions to list and detect each data type is a no-go.

Example Usage

For the function detectType(), the following should hold true:

detectType(1);           // Output: 'number'
detectType(new Map());   // Output: 'map'
detectType([]);          // Output: 'array'
detectType(null);        // Output: 'null'

![cover](https://storage.googleapis.com/algodailyrandomassets/curriculum/frontend/interview-questions/get-data-type.jpg)

You can see the full challenge with visuals at this link.

Challenges • Asked almost 3 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Jun 04, 2022:

This is the main discussion thread generated for Get Data Type (Main Thread).