|
5 | 5 |
|
6 | 6 | <head> |
7 | 7 | <meta charset=utf-8> |
8 | | - |
| 8 | + |
9 | 9 | <title> |
10 | 10 | Determine Datatypes In Javascript |
11 | 11 | </title> |
12 | | - |
| 12 | + |
13 | 13 | <meta name=description content='Learn how to determine data types in JavaScript. Explore interactive, editable code examples that let you test and understand type detection in real time.'> |
14 | 14 | <link rel=icon type='image/png' href='/blog/image/blog-30.png'> |
15 | 15 | <meta name=viewport content='width=device-width, initial-scale=1'> |
16 | | - |
| 16 | + |
17 | 17 | <base href='https://ext-code.com/blog/25-08-07/determine-datatypes-in-javascript/'> |
18 | 18 | <link rel=canonical href='https://ext-code.com/blog/25-08-07/determine-datatypes-in-javascript/determine-datatypes-in-javascript.html'> |
19 | 19 |
|
20 | | - |
21 | | - <script type='application/ld+json'> |
| 20 | + |
| 21 | + <script type='application/ld+json'> |
22 | 22 | { |
23 | 23 | "@context" : "https://schema.org", |
24 | 24 | "@type" : "TechArticle", |
|
29 | 29 | "dateModified" : "2025-10-29", |
30 | 30 | "mainEntityOfPage" : {"@type":"WebPage","@id":"https://ext-code.com/blog/25-08-07/determine-datatypes-in-javascript/determine-datatypes-in-javascript.html"}, |
31 | 31 | "publisher" : {"@type":"Organization","name":"Your Blog or Company Name","logo":{"@type":"ImageObject","url":"https://ext-code.com/favicon.ico"}}, |
32 | | - } |
| 32 | + } |
33 | 33 | </script> |
34 | 34 | <!-- |
35 | 35 | "image" : "https://yourdomain.com/images/http2-nodejs-demo.png" |
|
42 | 42 |
|
43 | 43 |
|
44 | 44 | <script src='https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js'></script> |
45 | | - |
46 | | - |
| 45 | + |
| 46 | + |
47 | 47 | <script src='https://libs.ext-code.com/js/dom/component/component.js'></script> |
48 | | - |
49 | | - |
| 48 | + |
| 49 | + |
50 | 50 | <script init> |
51 | 51 | console.clear(); |
52 | 52 | console.log('determine-datatypes-in-javascript.html'); |
53 | 53 | console.log(); |
54 | 54 | console.json=v=>console.log(JSON.stringify(v,null,4)); |
55 | 55 | var df=true,version='v2.0' |
56 | 56 | ; |
57 | | - |
58 | | - |
| 57 | + |
| 58 | + |
59 | 59 | var ace; |
60 | | - |
| 60 | + |
61 | 61 | var ext; |
62 | 62 | var $; |
63 | 63 | var datatype; |
|
70 | 70 | var ex2; |
71 | 71 | var ex3; |
72 | 72 | var log; |
73 | | - |
| 73 | + |
74 | 74 |
|
75 | 75 | //: |
76 | | - |
77 | | - |
| 76 | + |
| 77 | + |
78 | 78 | async function init(){ |
79 | 79 | debug('init',version); |
80 | 80 | menu = menumod(); |
81 | | - |
| 81 | + |
82 | 82 | mod.base.add({ext,$,datatype,keydown,menu,menumod,ace}); |
83 | 83 |
|
84 | | - |
85 | | - hdr = mod['blog-hdr']; |
| 84 | + |
| 85 | + hdr = mod['blog-hdr']; |
86 | 86 | ex1 = mod.ex1; |
87 | 87 | ex2 = mod.ex2; |
88 | 88 | ex3 = mod.ex3; |
|
104 | 104 |
|
105 | 105 |
|
106 | 106 | initdom(document.body); |
107 | | - |
108 | | - |
| 107 | + |
| 108 | + |
109 | 109 | }//init |
110 | | - |
111 | | - |
| 110 | + |
| 111 | + |
112 | 112 | (async()=>{ |
113 | 113 |
|
114 | 114 | mod.stack.add; |
115 | 115 |
|
116 | 116 | ({ext} = await import('https://libs.ext-code.com/js/io/ext-loader/ext-loader.m.js')); |
117 | | - |
| 117 | + |
118 | 118 | var promise = ext.load.libs( |
119 | 119 | 'js/dom/$.js', |
120 | 120 | 'js/core/datatype.js', |
|
123 | 123 | 'js/debug/debug.js', |
124 | 124 | ); |
125 | 125 | [$,datatype,menumod,keydown,debug] = await promise; |
126 | | - |
| 126 | + |
127 | 127 | mod.stack.complete; |
128 | | - |
| 128 | + |
129 | 129 | })(); |
130 | 130 |
|
131 | | - |
132 | | - </script init> |
133 | | - |
134 | 131 |
|
| 132 | + </script init> |
| 133 | + |
| 134 | + |
135 | 135 | <style> |
136 | 136 |
|
137 | 137 | html |
|
146 | 146 | [component] |
147 | 147 | {display:none} |
148 | 148 |
|
149 | | - .description |
| 149 | + .description |
150 | 150 | {max-width:1000px;text-align:justify;border-left:4px solid #4a90e2;padding:1rem 2rem; |
151 | 151 | background-color:#f9f9f9;font-family:system-ui,sans-serif;font-size:1rem;line-height:1.6;color:#333} |
152 | 152 | .description>p |
153 | 153 | {margin:0} |
154 | 154 | .description > p+p |
155 | 155 | {margin:10px 0} |
156 | | - |
| 156 | + |
157 | 157 | code |
158 | 158 | {font-family:monospace;background:whitesmoke} |
159 | 159 | code.inline |
160 | 160 | {display:inline;padding:5px 10px} |
161 | | - |
| 161 | + |
162 | 162 | a |
163 | 163 | {color:#4a90e2;text-decoration:none;font-weight:500} |
164 | | - a:hover |
| 164 | + a:hover |
165 | 165 | {text-decoration:underline} |
166 | 166 | .link-domain |
167 | 167 | {font-size:0.85rem;color:#777;margin-left:0.25rem} |
168 | | - .link-domain::before |
| 168 | + .link-domain::before |
169 | 169 | {content:'['} |
170 | 170 | .link-domain::after |
171 | 171 | {content:']'} |
172 | 172 | .link-txt |
173 | 173 | {} |
174 | | - |
| 174 | + |
175 | 175 | input |
176 | 176 | {font-size:16px;padding:5px 7px;box-sizing:border-box;} |
177 | 177 | input[type=button] |
178 | 178 | {cursor:pointer} |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | + |
183 | 183 |
|
184 | 184 | h3 |
185 | 185 | {text-align:center;color:blue} |
|
200 | 200 |
|
201 | 201 |
|
202 | 202 | </style> |
203 | | - |
| 203 | + |
204 | 204 | </head> |
205 | 205 |
|
206 | 206 |
|
207 | 207 | <body> |
208 | | - |
209 | | - |
210 | | - <blog-hdr component=grp1> |
| 208 | + |
| 209 | + |
| 210 | + <blog-hdr component=grp1> |
211 | 211 | <h1 class=title> |
212 | 212 | Determine Datatypes In Javascript |
213 | 213 | </h1> |
214 | 214 | <time slot=date datetime=2025-10-29> |
215 | 215 | 29 Oct 2025 |
216 | 216 | </time> |
217 | 217 | </blog-hdr> |
218 | | - |
| 218 | + |
219 | 219 | <div class=description> |
220 | 220 | <p> |
221 | 221 | Learn how to determine data types in JavaScript. Explore interactive, editable code examples that let you test and understand type detection in real time. |
222 | 222 | </p> |
223 | 223 | </div> |
224 | | - |
| 224 | + |
225 | 225 | <div class=description> |
226 | 226 | Determining datatypes in javascript always seemed to be a bit of a mystery, I've seen hundreds |
227 | | - of incarnations over the years, some work in some circumstances, until the code starts to get more |
| 227 | + of incarnations over the years, some work in some circumstances, until the code starts to get more |
228 | 228 | complex and then just mysteriously stop working, my go to for datatype has always been the following : |
229 | 229 | </div> |
230 | | - |
| 230 | + |
231 | 231 | <snippet-console id=ex1 src='ex/ex1.js' component></snippet-console> |
232 | | - |
233 | | - |
| 232 | + |
| 233 | + |
234 | 234 | <div class=break></div> |
235 | 235 |
|
236 | 236 |
|
237 | 237 | <div> |
238 | 238 | This can be extended further through the use of |
| 239 | + <br> |
| 240 | + <b> |
| 241 | + datatype |
| 242 | + </b> |
| 243 | + given here as a one liner |
239 | 244 | </div> |
240 | 245 |
|
241 | 246 | <snippet-console id=ex2 src='ex/ex2.js' component></snippet-console> |
242 | 247 |
|
243 | | - |
244 | | - <div class=break></div> |
245 | | - |
246 | | - |
| 248 | + |
| 249 | + <div class=break></div> |
| 250 | + |
| 251 | + |
247 | 252 | <div> |
248 | | - Instanceof is unreliable in the follow scenario |
| 253 | + Instanceof is unreliable in common scenarios |
249 | 254 | </div> |
250 | 255 |
|
251 | 256 | <snippet-console id=ex3 src='ex/ex3.js' component></snippet-console> |
252 | | - |
253 | | - |
| 257 | + |
| 258 | + |
254 | 259 | <log-mod component></log-mod> |
255 | 260 |
|
256 | 261 |
|
257 | | - </body> |
| 262 | + </body> |
258 | 263 |
|
259 | 264 |
|
260 | 265 | <!-- ----- --> |
261 | 266 |
|
262 | 267 |
|
263 | 268 | <script> |
264 | | - |
265 | | - |
266 | | - |
| 269 | + |
| 270 | + |
| 271 | + |
267 | 272 | //: |
268 | 273 |
|
269 | 274 |
|
270 | 275 | function initdom(rootnode){ |
271 | | - |
272 | | - |
| 276 | + |
| 277 | + |
273 | 278 | root = rootnode; |
274 | | - |
| 279 | + |
275 | 280 | hdr.initdom(); |
276 | 281 | ex1.initdom(); |
277 | 282 | ex2.initdom(); |
278 | 283 | ex3.initdom(); |
279 | 284 |
|
280 | 285 |
|
281 | 286 | log.initdom(); |
282 | | - |
283 | | - |
284 | | - }//initdom |
285 | 287 |
|
286 | | - |
| 288 | + |
| 289 | + }//initdom |
| 290 | + |
| 291 | + |
287 | 292 | //: |
288 | 293 |
|
289 | 294 |
|
290 | 295 |
|
291 | 296 |
|
292 | | - |
| 297 | + |
293 | 298 | </script> |
294 | 299 |
|
295 | 300 |
|
|
0 commit comments