Skip to content

Commit

Permalink
Create 2012-12-28-undefined-props-on-numbers.md
Browse files Browse the repository at this point in the history
New post about unexpected undefined properties on numbers

Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
  • Loading branch information
unwiredben authored and DTrejo committed Jan 29, 2013
1 parent ec35a2e commit 3e2d387
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -29,4 +29,4 @@
"wtfjs.com",
"www.wtfjs.com"
]
}
}
15 changes: 15 additions & 0 deletions posts/2012-12-28-undefined-props-on-numbers.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3e2d387

Please sign in to comment.