DEV Community

Understanding Data Types in JavaScript

Himanshu Gupta on February 26, 2024

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 c...
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