['1','2','3'].map(parseInt);
[typeof null,null instanceOf Object]
[[3,2,1].reduce(Math.pow),[].reduce(Math.pow)]
var val = 'smtg'; console.log('value is' + (val === 'smtg') ? 'Something' : 'Nothing');
var name = 'World'; (function(){ if (typeof name === 'undefined') { var name = 'jack'; console.log('Goodbye' + name); } else { console.log('Hello' + name); } })();
var END = Math.pow(2,53); var START = END - 100; var count = 0; for(var i = START; i <= END; i++){ count++; } console.log(count);
var arr = [0,1,2]; arr[10] = 10; arr.filter(function(x){ return x === undefined});
var two = 0.2; var one = 0.1; var eight = 0.8; var six = 0.6; [two - one == one, eight - six == two]
function showCase(value){ switch(value){ case 'A': console.log('Case A'); break; case 'B': console.log('Case B'); break; case undefined: console.log('undefined'); break; default: console.log('unknown'); break; } } showCase(new String('A'))
function showCase(value){ switch(value){ case 'A': console.log('Case A'); break; case 'B': console.log('Case B'); break; case undefined: console.log('undefined'); break; default: console.log('unknown'); break; } } showCase(String('A'))
function isOdd(num){ return num % 2 == 1; } function isEven(num){ return num % 2 == 0; } function isSane(num){ return isEven(num) || isOdd(num); } var values = [7, 4, '13', -9, Infinity]; values.map(isSane);
Array.isArray(Array.prototype);
var a = [0]; if([0]){ console.log(a == true); }else{ console.log('wut'); }
parseInt(3, 8); parseInt(3, 2); parseInt(3, 0);
[] == [];
'5' + 3; '5' - 3;
1 + - + + + - + 1
var arr = Array(3); arr[0] = 2; arr.map(function(item){ return '1'; });
function sidEffecting(arr){ arr[0] = arr[2]; } function bar(a, b, c){ c = 10; sidEffecting(arguments); return a + b + c; } bar(1,1,1);
var a = 11111111111111000; var b = 111; console.log(a + b);
var x = [].reverse; x();
Number.MIN_VALUE > 0; // MIN_VALUE 屬性是 JavaScript 中可表示的最小的數(接近 0 ,但不是負數)。它的近似值爲 5 x 10-324
[1 < 2 < 3, 3 < 2 < 1];
2 == [[[2]]]
3.toString(); 3..toString(); 3...toString();
(function(){ var x = y = 1; })(); x; y;
var a = /123/; var b = /123/; a == b; a === b;
var a = [1, 2, 3]; var b = [1, 2, 3]; var c = [1, 2, 4]; a == b; a === b; a > c; a < c;
var a = {}; var b = Object.prototype; [a.prototype === b, Object.getPrototypeOf(a) === b];
function f(){}; var a = f.prototype, b = Object.getPrototypeOf(f); a === b;
function foo(){} var oldName = foo.name; foo.name = 'bar'; [oldName, foo.name];
'1 2 3'.replace(/\d/g,parseInt);
function f(){} var parent = Object.getPrototypeOf(f); f.name; //? parent.name; //? typeof eval(f.name) //? typeof eval(parent.name) //?
var lowerCaseOnly = /^[a-z]+$/; [lowerCaseOnly.test(null), lowerCaseOnly.test()];
[,,,].join(', ');
var a = {class:'Animal', name:'Fido'}; a.class;
var a = new Date('epoch');
var a = Function.length; var b = new Function().length; a === b;
var b = Date(0); var b = new Date(0); var c = new Date(); [a === b, b === c, a === c]
var min = Math.min(), max = Math.max(); min < max;
function captureOne(re, str){ var match = re.exec(str); return match && match[1]; } var numRe = /num=(\d+)/ig; var wordRe = /word=(\w+)/i; a1 = captureOne(numRe, 'num=1'); a2 = captureOne(wordRe, 'word=1'); a3 = captureOne(numRe, 'NUM=2'); a4 = captureOne(wordRe, 'WORD=2'); [a1 === a2, a3 === a4]
var a= new Date('2014-03-19'); var b =new Date(2014, 03, 19); [a.getDay() === b.getDay(), a.getMonth() === b.getMonth()]
if('http://xxxgif.com/picture.jpg'.match('.gif')){ 'a gif file' }else{ 'note a git file' }
function foo(a){ var a; return a; } function bar(a){ var a = 'bye'; return a; } [foo('hello'),bar('hello')];
本文僅供分享學習使用若是您發現侵犯了您的權益,請及時告知本人,以便及時刪除該文章。
git