From 31d41352ffaeb95e77241022c6a01ba6c765d093 Mon Sep 17 00:00:00 2001 From: atomiks Date: Mon, 1 Jan 2018 04:27:20 +1100 Subject: [PATCH] Optimize --- snippets/isPrimitive.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/isPrimitive.md b/snippets/isPrimitive.md index cd90501b3..3abe155c4 100644 --- a/snippets/isPrimitive.md +++ b/snippets/isPrimitive.md @@ -2,12 +2,12 @@ Returns a boolean determining if the supplied value is primitive or not. -Use `Array.includes()` on an array of type strings, supplying the type using `typeof`. +Use `Array.includes()` on an array of type strings which are not primitive, +supplying the type using `typeof`. Since `typeof null` evaluates to `'object'`, it needs to be directly compared. ```js -const isPrimitive = value => - ['string', 'number', 'symbol', 'boolean', 'undefined'].includes(typeof value) || value === null; +const isPrimitive = val => !['object', 'function'].includes(typeof val) || val === null; ``` ```js