Javascript, The Bad Parts
By Daniel Huckstep
All sorts of bad things happen when you use the bad parts
Like bugs. And nobody likes bugs.
Global Variables
You're being trolled by the environment
- Variables are global unless otherwise defined.
- Since when is that a good idea?
Block Syntax, with no Block Scope
Every other language you'd want to use has block scope.
But not Javascript.
Automatic Semicolon Insertion
You're being trolled by the interpreter
- Some minifiers don't play nice with it.
- Can result in more (subtle) bugs..
Characters are 16-bits
You're being trolled by the locale
Need more than 16-bits for a character? Cool story bro.
parseInt
It takes an extra argument you know...
- That extra argument is the radix.
- If you don't specify it, it does fun things. Like parse base 8 randomly.
+ operator
Adding or concatenation, depending on the arguments
If the arguments are different, it does some coercion. Because that's probably what you want.
typeof NaN === "number"
Think about that.
typeof [] === "object"
Javascript arrays are just weird objects.
for-in loops don't really work.
== and ===
Do you want bizarre coercion or an actual equals operator that works as you expect it to?
with
You're being trolled by the property lookup chain.
Make code less readable and slower.
Why is it a good thing again?
eval
Can you spell slow security hole?
Minimizers hate eval too.
setTimeout/setInterval
They can take strings, which is just as bad as eval.
case fallthrough
Fallthrough is default, have to use break
Ruby does it right (no fallthrough or break at all), so does Go (explicit fallthrough)
if/while/etc don't require braces
Go finally does this right.
bitwise operators
Convert internally to int, do the operation, then back to float.
wat.