632 B
632 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | |
|---|---|---|---|---|---|---|
| Number is primitive | snippet | javascript |
|
flower-camera | 2020-10-22T20:23:47+03:00 |
Checks if the passed value is primitive or not.
- Create an object from
valand compare it withvalto 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