Files
30-seconds-of-code/snippets/isPrimitive.md
Angelos Chalaris 5e42f0aaa4 Add some examples
From the old test suite
2020-04-16 23:01:19 +03:00

582 B

title, tags
title tags
isPrimitive type,function,array,string,intermediate

Returns a boolean determining if the passed value is primitive or not.

Create an object from val and compare it with val to determine if the passed value is primitive (i.e. not equal to the created object).

const isPrimitive = val => Object(val) !== val;
isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive(50); // true
isPrimitive('Hello!'); // true
isPrimitive(false); // true
isPrimitive(Symbol()); // true
isPrimitive([]); // false
isPrimitive({}); // false