JavaScript Grievances
JavaScript Grievances
common complaints about JavaScript
Seinfeld Festivus Airing of Grievances
Copyright ? 2012-2013 by Object Computing, Inc. (OCI). All rights reserved.
Assessment Key
E - Addressed by EcmaScript 6 (ES6) D - Doesn't really happen in practice L - Caught by Linting tools (JSLint/JSHint) and/or ES5 strict mode P - Personal preference R - Real problem Y - You can easily learn how to deal with this
Copyright ? 2012-2014 by Object Computing, Inc. (OCI). All rights reserved.
10 - 2
JS Grievances
Crockford's Bad Parts ...
Implied globals (E, L)
assign to a variable without a var and it becomes global can't do in strict mode in ES6, use let instead of var
Scope (E, Y)
variables are scoped to a function body or they are global no block scope in things like if statements and loops (see let in ES6) CoffeeScript and Node.js provide file/module-scoped variables
Semicolon insertion (D, L)
semicolons are optional when omitted, they are automatically inserted, sometimes not where intended hard to get wrong though
Copyright ? 2012-2014 by Object Computing, Inc. (OCI). All rights reserved.
10 - 3
JS Grievances
... Crockford's Bad Parts ...
Reserved words (L)
many aren't currently used, but reserved for possible future use don't have to memorize them; let a lint tool warn you
Unicode (E, D)
uses UTF-16 characters, not UTF-8, and string methods expect only 2-byte characters, not 4 characters in all modern languages only require 2 bytes
typeof (Y)
typeof null === 'object' and typeof [1, 2, 3] === 'object'
Numbers (E, D)
all are represented by a double; no integer type, but can accurately represent up to 53 bits which is large enough for almost all uses
Copyright ? 2012-2014 by Object Computing, Inc. (OCI). All rights reserved.
10 - 4
JS Grievances
... Crockford's Bad Parts
Arrays (E, D)
represents arrays as objects where keys are string versions of indexes a potential performance issue; but not typically ES6 adds typed arrays of numbers
Falsy values (Y)
false, undefined, null, 0, NaN and "" are all treated as false in boolean contexts
everything else is truthy
== vs. === and != vs. !== (L)
short forms perform type coercion, long forms do not
eval(code) (D, L)
need to be careful about source of code
Copyright ? 2012-2014 by Object Computing, Inc. (OCI). All rights reserved.
10 - 5
JS Grievances
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- javascript invert array
- javascript array syntax
- javascript array to string
- javascript array update existing element
- javascript array functions
- javascript convert array to string
- javascript change array element
- javascript array variable
- javascript parse string to date
- javascript function array argument
- javascript update item in array
- javascript array of objects example