💾isPrimitive()
check if value is a primitive
JS ⟩ values ⟩ custom functions ⟩ isPrimitive()
replit:isPrimitive()
┌── (primitive ?)
│ typeof type expr value
---------------------------------------------------------------------
✅ object Null null null
---------------------------------------------------------------------
✅ undefined Undefined undefined undefined
---------------------------------------------------------------------
✅ number Number 37 37
✅ number Number 3.14 3.14
✅ number Number Math.LN2 0.6931471805599453
✅ number Number Infinity Infinity ⭐️
✅ number Number NaN NaN ⭐️
✅ number Number Number('1') 1
✅ number Number Number('ab') NaN
---------------------------------------------------------------------
✅ bigint BigInt 42 42n
---------------------------------------------------------------------
✅ string String 'bla' 'bla'
✅ string String `x = ${1+2}` 'x = 3'
✅ string String typeof 1 'number'
✅ string String String({}) '[object Object]'
✅ string String typeof xxx 'undefined'
---------------------------------------------------------------------
✅ boolean Boolean true true
✅ boolean Boolean Boolean(1) true
✅ boolean Boolean !!(1) true
---------------------------------------------------------------------
✅ symbol Symbol Symbol() Symbol()
✅ symbol Symbol Symbol.iterator Symbol(Symbol.iterator)
---------------------------------------------------------------------
❌ object Object {a:1} { a: 1 }
❌ object User user User { name: 'JohnDoe' }
❌ object Array [1, 2] [ 1, 2 ]
❌ object Date new Date() 2022-09-13T01:47:46.344Z
❌ object RegExp /regex/ /regex/
---------------------------------------------------------------------
❌ function Function function(){} [Function (anonymous)]
❌ function Function Math.sin [Function: sin]
❌ function Function () => {} [Function (anonymous)]
❌ function class class {} [class (anonymous)]
❌ function class User [class User]
❌ function GeneratorFunction function*(){} [GeneratorFunction (anonymous)]
---------------------------------------------------------------------
Last updated
Was this helpful?