10 examples of 'js typeof' in JavaScript

Every line of 'js typeof' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
16function _typeof(obj) {
17 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
18 _typeof = function (obj) {
19 return typeof obj;
20 };
21 } else {
22 _typeof = function (obj) {
23 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
24 };
25 }
26
27 return _typeof(obj);
28}
18function _typeof(obj) {
19 if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
20 _typeof = function _typeof(obj) {
21 return typeof obj;
22 };
23 } else {
24 _typeof = function _typeof(obj) {
25 return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype
26 ? 'symbol'
27 : typeof obj;
28 };
29 }
30 return _typeof(obj);
31}
18function _typeof(obj) {
19 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
20 _typeof = function _typeof(obj) {
21 return typeof obj;
22 };
23 } else {
24 _typeof = function _typeof(obj) {
25 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
26 };
27 }
28 return _typeof(obj);
29}
19utils.typeOf = function typeOf (val) {
20 return Array.isArray(val) ? 'array' : typeof val
21}
144function typeOf(value) {
145 if (Array.isArray(value)) {
146 return 'array';
147 }
148 if (value === null) {
149 return 'null';
150 }
151 return typeof value;
152}
53function typeOf(value) {
54 var t = typeof(value);
55 if (t === 'object') {
56 if (value) {
57 if (value instanceof Array) {
58 t = 'array';
59 }
60 }
61 else {
62 t = 'null';
63 }
64 }
65 return t;
66}
154function typeOf(value) {
155 var s = typeof value;
156 if (s === 'object') {
157 if (value) {
158 if (typeof value.length === 'number' &&
159 !(value.propertyIsEnumerable('length')) &&
160 typeof value.splice === 'function') {
161 s = 'array';
162 }
163 } else {
164 s = 'null';
165 }
166 }
167 return s;
168}
14function typeOf(val) {
15 switch (toString.call(val)) {
16 case '[object Function]':
17 return 'function';
18 case '[object Date]':
19 return 'date';
20 case '[object RegExp]':
21 return 'regexp';
22 case '[object Arguments]':
23 return 'arguments';
24 case '[object Array]':
25 return 'array';
26 case '[object String]':
27 return 'string';
28 }
29
30 if (typeof val == 'object' && val && typeof val.length == 'number') {
31 try {
32 if (typeof val.callee == 'function') return 'arguments';
33 } catch (ex) {
34 if (ex instanceof TypeError) {
35 return 'arguments';
36 }
37 }
38 }
39
40 if (val === null) return 'null';
41 if (val === undefined) return 'undefined';
42 if (val && val.nodeType === 1) return 'element';
43 if (val === Object(val)) return 'object';
44
45 return typeof val;
46}
77function getTypeOf(obj) {
78 const { toString } = Object.prototype
79 const map = {
80 '[object Boolean]': 'boolean',
81 '[object Number]': 'number',
82 '[object String]': 'string',
83 '[object Function]': 'function',
84 '[object Array]': 'array',
85 '[object Date]': 'date',
86 '[object RegExp]': 'regExp',
87 '[object Undefined]': 'undefined',
88 '[object Null]': 'null',
89 '[object Object]': 'object',
90 '[object Symbol]': 'symbol',
91 }
92 return map[toString.call(obj)]
93}
368typeOf: function typeOf(obj) {
369 return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
370},

Related snippets