use typeof
to get the type of a object
typeof 123; // 'number'
typeof NaN; // 'number'
typeof 'str'; // 'string'
typeof true; // 'boolean'
typeof undefined; // 'undefined'
typeof Math.abs; // 'function'
typeof null; // 'object'
typeof []; // 'object'
typeof {}; // 'object'
null
is object, Array
is object
Note:
- Do ## NOT ## use
new Number()、new Boolean()、new String()
to create wrapper object - Use
String
to convert any type to string, or usetoString()
for a object - Do not need to convert any type to
boolean
typeof
could getnumber、boolean、string、function and undefined
- Use
Array.isArray(arr)
- Use
myVar === null
Create a date object:
var d = new Date(2015, 5, 19, 20, 15, 30, 123);
d; // Fri Jun 19 2015 20:15:30 GMT-0700 (Pacific Daylight Time)
var re1 = /ABC\-001/
var re2 = new RegExp('ABC\\-001');
re.test('mock string'); // return true or false
- Group:
exec()
- Greedy match:
?
- Global search:
g
Data type:
- number
- boolean
- string
- null
- array -- []
- object -- { ... }
Must use " "
JSON.stringfy(object)
convert object to string with JSON format
JSON.parse(JSON)
convert JSON format string to object