Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create 2012-12-28-undefined-props-on-numbers.md

New post about unexpected undefined properties on numbers

Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
  • Loading branch information...
commit 3e2d38743e55a493a74d8b61ca6f0ca2f0396037 1 parent ec35a2e
@unwiredben unwiredben authored DTrejo committed
View
1  README.md
@@ -72,3 +72,4 @@ Ordered by date of first contribution.
- [Jamund Ferguson aka `xjamundx`](https://github.com/xjamundx)
- [Thaddee Tyl aka `espadrine`](https://github.com/espadrine)
- [Stanley Stuart aka `fivetanley`](https://github.com/fivetanley)
+- [Ben Combee aka `unwiredben`](https://github.com/unwiredben)
View
4 package.json
@@ -1,7 +1,7 @@
{
"name": "wtf",
"description": "The wtfs of javascript at wtfjs.com",
- "version": "0.2.0-21",
+ "version": "0.2.0-24",
"homepage": "wtfjs.com",
"repository": {
"type": "git",
@@ -29,4 +29,4 @@
"wtfjs.com",
"www.wtfjs.com"
]
-}
+}
View
15 posts/2012-12-28-undefined-props-on-numbers.md
@@ -0,0 +1,15 @@
+```
+ function getBounds(node) {
+ var n = node || 0;
+ return { width: n.width, height: n.height };
+ }
+```
+
+If you call `getBounds()` with _null_, you'll get back `{ width: undefined, height: undefined }`
+because in JS, numbers have properties (inherited from Number), and using an undefined
+property doesn't throw, it just returns undefined. `null` and `undefined` are propertyless.
+Definitely not what I expected in a quick reading of code like this.
+
+— [@unwiredben][1]
+
+[1]:https://twitter.com/unwiredben
Please sign in to comment.
Something went wrong with that request. Please try again.