@ Netscape in 1995 to parody VB
Codename called Mocha, later LiveScript in Navigator 2.0 Beta
- Everything You Never Wanted To Know About JavaScript Numbers
- object like (has methods)
- immutable (by value)
- type detection:
typeof value === 'number' && isFinite(value) - creation
00.0
- typecast
Number(value)+valueparseFloat(value, 10)parseInt(value, 10)
- useful methods
.toString().toFixed(units).toPrecision(digits)
- gotcha!
typeof NaN === 'number'typeof Infinity === 'number'
- object like (has methods)
- immutable (by value)
- type detection:
typeof value === 'string' - creation
"value"'value'String(value)
- typecast
String(value)value + ''value.toString()(where available)
- useful methods
.charAt(index).fromCharCode(asciiCode).indexOf(character).toUpperCase().toLowerCase().substr(start, length).substring(start, end).split(char)
- object like (has methods)
- immutable (by value)
- creation
truefalse
- typecast
!!value
- useful methods
.toString()
- on the global :(
- can be overwritten :(
- type detection:
typeof value === 'undefined'
- a literal \o/!
- used to clear out a variables value (don't use undefined)
- type detection:
value === null
- mutable (by reference)
- keyed collections
- type detection:
obj && typeof obj === 'object' - look up:
obj.keyobj['key'] - creation
{ }
- useful methods
.hasOwnProperty(value).__proto__(inheritance?)
- JSON
JSON.stringify(obj)JSON.parse(str)
- type detection:
Object.prototype.toString.call(arr) === '[object Array]' - look up:
arr[index] - creation
[ ]
- useful methods
.sort().indexOf().push().pop().shift().unshift().slice(start[, end]).splice(index, howManyToRemove[, nItemsToAdd])
- type detection:
typeof fn === 'function' - hoisted
- creation
function () {}funciton Name () {}
- useful methods
.apply().call()
- type detection:
Object.prototype.toString.call(reg) === '[object RegExp]' - creation
/./new RegExp('.')
- useful methods
.test(str).exec(str)