DEV Community

Himanshu Gupta
Himanshu Gupta

Posted on

1 1 1 1 1

Understanding Data Types in JavaScript

In JavaScript, data types play a crucial role in defining the nature of variables and how they behave in our code. Broadly, JavaScript data types can be classified into two categories: Primitive and Non-Primitive (also known as Reference or Object) data types.

Primitive Data Types
Primitive data types are immutable and hold primitive values directly. They are the basic building blocks of data manipulation in JavaScript. Let's take a closer look at each primitive data type along with its typeof output:

Image description

  1. Number: Represents numeric values.
  2. String: Represents textual data.
  3. Boolean: Represents true or false values.
  4. BigInt: Represents integers with arbitrary precision.
  5. Symbol: Represents unique identifiers.
  6. Null: Represents the absence of any value.
  7. Undefined: Represents a variable that has been declared but has not been assigned a value.

Non-Primitive Data Types
Non-primitive data types are mutable and store references to memory locations. They are more complex data structures and include objects, arrays, and functions.

Image description

  1. Object: Represents a collection of key-value pairs. 2, Array: Represents a collection of elements arranged in an ordered list. 3, Function: Represents executable code blocks that can be invoked.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (2)

Collapse
 
efpage profile image
Eckehard • Edited

Javascript is a dynamically typed language, so a variable can contain anything. The more important it is to have working type checks. Here is a list of functions I am using. I was happy to get some additions/corrections on this:

  isArr = Array.isArray
  isEle = (c) => c instanceof Element
  isNode = (c) => c instanceof Node
  isStr = (s) => typeof s === 'string'
  isObj = (c) => typeof c === 'object' && !isArr(c) && c !== null
  isDef = (c) => typeof c !== "undefined";
  isNum = (c) => typeof c === "number";
  isFnc = (c) => typeof c === "function";
  isEmpty = (s) => s.length === 0
  isBlank = (s) => s.trim().length === 0
Enter fullscreen mode Exit fullscreen mode
Collapse
 
himanshudevgupta profile image
Himanshu Gupta

@efpage Thankyou for update

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay